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

  1. package main
  2. import (
  3. "fmt"
  4. "unicode"
  5. )
  6. func passwordChecker(pw string) bool {
  7. pwR := []rune(pw)
  8. if len(pwR) < 8 || len(pwR) > 15 {
  9. return false
  10. }
  11. hasUpper := false
  12. hasLower := false
  13. hasNumber := false
  14. hasSymbol := false
  15. for _, v := range pwR {
  16. if unicode.IsUpper(v) {
  17. hasUpper = true
  18. }
  19. if unicode.IsLower(v) {
  20. hasLower = true
  21. }
  22. if unicode.IsNumber(v) {
  23. hasNumber = true
  24. }
  25. if unicode.IsPunct(v) || unicode.IsSymbol(v) {
  26. hasSymbol = true
  27. }
  28. }
  29. return hasUpper && hasLower && hasNumber && hasSymbol
  30. }
  31. func main() {
  32. if passwordChecker("") {
  33. fmt.Println("Password good")
  34. } else {
  35. fmt.Println("Password bad")
  36. }
  37. if passwordChecker("This!I5A") {
  38. fmt.Println("Password good")
  39. } else {
  40. fmt.Println("Password bad")
  41. }
  42. }