码迷,mamicode.com
首页 > 其他好文 > 详细

密码验证合格程序

时间:2020-02-23 00:01:52      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:pass   pre   code   数字   输出   密码验证   NPU   cep   while   

题目描述
密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有相同长度超2的子串重复
说明:长度超过2的子串
输入描述:
一组或多组长度超过2的子符串。每组占一行
输出描述:
如果符合要求输出:OK,否则输出NG


解法1(Python3):

import re
import sys

for line in sys.stdin:
    line = line.strip()
    if len(line) <= 8:
        print(‘NG‘)
        continue
    count = 0
    if re.search(‘[a-z]+‘, line) is not None:
        count += 1
    if re.search(‘[A-Z]+‘, line) is not None:
        count += 1
    if re.search(‘[0-9]+‘, line) is not None:
        count += 1
    if re.search(‘[^a-zA-Z0-9]+‘, line) is not None:
        count += 1
    if count < 3:
        print(‘NG‘)
        continue
    for i in range(len(line)-3):
        if line.count(line[i:i+3]) > 1:
            print(‘NG‘)
            break
    else:
        print(‘OK‘)

解法2(Python3):

import re

try:
    while True:
        s = input()
        a = re.findall(r‘.*(.{3,}).*\1‘, s)
        b1 = re.findall(r‘[0-9]‘, s)
        b2 = re.findall(r‘[A-Z]‘, s)
        b3 = re.findall(r‘[a-z]‘, s)
        b4 = re.findall(r‘[^0-9A-Za-z]‘, s)
        if [b1, b2, b3, b4].count([]) <= 1 and a == [] and len(s) > 8:
            print(‘OK‘)
        else:
            print(‘NG‘)
except:
    pass

密码验证合格程序

标签:pass   pre   code   数字   输出   密码验证   NPU   cep   while   

原文地址:https://blog.51cto.com/13614527/2472852

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!