updated parser
This commit is contained in:
1
main.go
1
main.go
@@ -29,6 +29,7 @@ func main() {
|
|||||||
// Fetch user input
|
// Fetch user input
|
||||||
fmt.Print("Enter your password: ")
|
fmt.Print("Enter your password: ")
|
||||||
fmt.Scanf("%s", &input)
|
fmt.Scanf("%s", &input)
|
||||||
|
fmt.Println(input)
|
||||||
|
|
||||||
// Check users password
|
// Check users password
|
||||||
message, err := password.Check(input, commonWords, commonPasswords)
|
message, err := password.Check(input, commonWords, commonPasswords)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check checks if password is valid, and returns message, and if its a strong password
|
// Check checks if password is valid, and returns message, and if its a strong password
|
||||||
@@ -23,30 +24,30 @@ func Check(input string, wordList, passwordList []string) (string, error) {
|
|||||||
|
|
||||||
// Check if password contains a number and a special character and a capital letter
|
// Check if password contains a number and a special character and a capital letter
|
||||||
for _, letter := range input {
|
for _, letter := range input {
|
||||||
// Check ASCII code to see if has special character
|
// Check if letter is a symbol
|
||||||
if letter >= 33 && letter <= 47 || letter >= 58 && letter <= 62 {
|
if !(unicode.IsLetter(letter) || unicode.IsDigit(letter) || unicode.IsSpace(letter)) {
|
||||||
hasSpecialCharacter = true
|
hasSpecialCharacter = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check ASCII code to see if password contains a number
|
// Check if letter is a number
|
||||||
if letter >= 48 && letter <= 57 {
|
if unicode.IsDigit(letter) {
|
||||||
hasNumber = true
|
hasNumber = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check ASCII code to see if password contains a capital letter
|
// Check if letter is a capital letter
|
||||||
if letter >= 65 && letter <= 90 {
|
if unicode.IsUpper(letter) {
|
||||||
hasCapitalLetter = true
|
hasCapitalLetter = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check ASCII code to see if there is a space
|
// Check for spaces
|
||||||
if letter == 32 {
|
if unicode.IsSpace(letter) {
|
||||||
return "Weak password", fmt.Errorf("password cannot contain a space")
|
return "Invalid password", fmt.Errorf("password cannot contain spaces")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if password is in common passwords
|
// Check if password is in common passwords
|
||||||
for _, entry := range passwordList {
|
for _, entry := range passwordList {
|
||||||
if strings.Contains(entry, input) {
|
if strings.Contains(strings.ToLower(entry), strings.ToLower(input)) {
|
||||||
return "Weak password", fmt.Errorf("password found inside common passwords")
|
return "Weak password", fmt.Errorf("password found inside common passwords")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,13 +58,13 @@ func Check(input string, wordList, passwordList []string) (string, error) {
|
|||||||
strippedPassword := re.ReplaceAllString(input, "")
|
strippedPassword := re.ReplaceAllString(input, "")
|
||||||
// Iterate through common words and see if input contains any
|
// Iterate through common words and see if input contains any
|
||||||
for _, word := range wordList {
|
for _, word := range wordList {
|
||||||
if strings.Contains(word, strippedPassword) {
|
if strings.Contains(strings.ToLower(word), strings.ToLower(strippedPassword)) {
|
||||||
return "Weak password", fmt.Errorf("password contains common word from wordlist")
|
return "Weak password", fmt.Errorf("password contains common word from wordlist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(hasNumber && hasSpecialCharacter && isTwelveCharacters && hasCapitalLetter) {
|
if !(hasNumber && hasSpecialCharacter && isTwelveCharacters && hasCapitalLetter) {
|
||||||
return "Weak password", nil
|
return "Weak password", fmt.Errorf("Has number: %v, Has special character: %v, Has 12+ characters: %v, Has capital letter: %v", hasNumber, hasSpecialCharacter, isTwelveCharacters, hasCapitalLetter)
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Strong password", nil
|
return "Strong password", nil
|
||||||
|
|||||||
Reference in New Issue
Block a user