打赏

golang密码校验

golang密码校验

func verifyPassword(s string) bool {
    var hasNumber, hasUpperCase, hasLowercase, hasSpecial bool
    for _, c := range s {
        switch {
        case unicode.IsNumber(c):
            hasNumber = true
        case unicode.IsUpper(c):
            hasUpperCase = true
        case unicode.IsLower(c):
            hasLowercase = true
        case c == '#' || c == '|':
            return false
        case unicode.IsPunct(c) || unicode.IsSymbol(c):
            hasSpecial = true
        }
    }
    return hasNumber && hasUpperCase && hasLowercase && hasSpecial
}
posted @ 2020-04-13 14:07  苍山落暮  阅读(1275)  评论(0编辑  收藏  举报