From 66a2eb9546350bccfde4ad0ff06e5757bd4bbfe4 Mon Sep 17 00:00:00 2001 From: Cereska <8877199733@cms.k12.nc.us> Date: Mon, 23 Feb 2026 08:46:15 -0500 Subject: [PATCH] updated parser --- main.go | 1 + password/password.go | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index e0860eb..1dc4a02 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ func main() { // Fetch user input fmt.Print("Enter your password: ") fmt.Scanf("%s", &input) + fmt.Println(input) // Check users password message, err := password.Check(input, commonWords, commonPasswords) diff --git a/password/password.go b/password/password.go index e07a557..3b4fb85 100644 --- a/password/password.go +++ b/password/password.go @@ -4,6 +4,7 @@ import ( "fmt" "regexp" "strings" + "unicode" ) // 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 for _, letter := range input { - // Check ASCII code to see if has special character - if letter >= 33 && letter <= 47 || letter >= 58 && letter <= 62 { + // Check if letter is a symbol + if !(unicode.IsLetter(letter) || unicode.IsDigit(letter) || unicode.IsSpace(letter)) { hasSpecialCharacter = true } - // Check ASCII code to see if password contains a number - if letter >= 48 && letter <= 57 { + // Check if letter is a number + if unicode.IsDigit(letter) { hasNumber = true } - // Check ASCII code to see if password contains a capital letter - if letter >= 65 && letter <= 90 { + // Check if letter is a capital letter + if unicode.IsUpper(letter) { hasCapitalLetter = true } - // Check ASCII code to see if there is a space - if letter == 32 { - return "Weak password", fmt.Errorf("password cannot contain a space") + // Check for spaces + if unicode.IsSpace(letter) { + return "Invalid password", fmt.Errorf("password cannot contain spaces") } } // Check if password is in common passwords 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") } } @@ -57,13 +58,13 @@ func Check(input string, wordList, passwordList []string) (string, error) { strippedPassword := re.ReplaceAllString(input, "") // Iterate through common words and see if input contains any 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") } } 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