forked from mandiant/gocrack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_check.go
More file actions
36 lines (31 loc) · 738 Bytes
/
password_check.go
File metadata and controls
36 lines (31 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package authentication
import (
"unicode"
)
// CheckPasswordRequirement ensures the password meets sane requirements of 8+ characters, at least one number,
// one special character, and both an upper and lowercase letter
func CheckPasswordRequirement(password string) bool {
if len(password) < 8 {
return false
}
var hasLetter, hasPunct, hasNum bool
for _, r := range password {
// gate: if we already have all the validations, bomb out
if hasLetter && hasPunct && hasNum {
return true
}
if unicode.IsNumber(r) {
hasNum = true
continue
}
if unicode.IsLetter(r) {
hasLetter = true
continue
}
if unicode.IsPunct(r) {
hasPunct = true
continue
}
}
return hasLetter && hasPunct && hasNum
}