-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: more informative error messages for password requirements (#549)
- Loading branch information
1 parent
7211d51
commit 6d608b0
Showing
8 changed files
with
109 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package auth | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/GenerateNU/sac/backend/src/constants" | ||
"github.com/GenerateNU/sac/backend/src/errors" | ||
) | ||
|
||
func ValidatePassword(password string) *errors.Error { | ||
if len(password) < 8 { | ||
return &errors.InvalidPasswordNotLongEnough | ||
} | ||
|
||
if !hasDigit(password) { | ||
return &errors.InvalidPasswordNoDigit | ||
} | ||
|
||
if !hasSpecialChar(password) { | ||
return &errors.InvalidPasswordNoSpecialCharacter | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func hasDigit(str string) bool { | ||
return regexp.MustCompile(`[0-9]`).MatchString(str) | ||
} | ||
|
||
func hasSpecialChar(str string) bool { | ||
for _, c := range constants.SPECIAL_CHARACTERS { | ||
if strings.Contains(str, string(c)) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters