Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

56 lines
833 B

package main
import (
"fmt"
"unicode"
)
func passwordChecker(pw string) bool {
pwR := []rune(pw)
if len(pwR) < 8 || len(pwR) > 15 {
return false
}
hasUpper := false
hasLower := false
hasNumber := false
hasSymbol := false
for _, v := range pwR {
if unicode.IsUpper(v) {
hasUpper = true
}
if unicode.IsLower(v) {
hasLower = true
}
if unicode.IsNumber(v) {
hasNumber = true
}
if unicode.IsPunct(v) || unicode.IsSymbol(v) {
hasSymbol = true
}
}
return hasUpper && hasLower && hasNumber && hasSymbol
}
func main() {
if passwordChecker("") {
fmt.Println("Password good")
} else {
fmt.Println("Password bad")
}
if passwordChecker("This!I5A") {
fmt.Println("Password good")
} else {
fmt.Println("Password bad")
}
}