zoukankan      html  css  js  c++  java
  • python实践项目六:正则表达式-强口令

    描述:写一个函数,它使用正则表达式,确保传入的口令字符串是强口令。强口令的定义是:长度不少于8 个字符,  同时包含大写和小写字符, 至少有一位数字。

    代码

     1 #!/usr/bin/python
     2 # -*- coding: UTF-8 -*-
     3 # 写一个函数,它使用正则表达式,确保传入的口令字符串是强口令。强口令的定义是:长度不少于8 个字符,
     4 # 同时包含大写和小写字符, 至少有一位数字。你可能需要用多个正则表达式来测试该字符串, 以保证它的强度。
     5 import re,pyperclip
     6 def detection(text):
     7     if (len(text)<8):
     8         return False
     9     number1=re.compile(r'd+') #创建一个正则表达式:任意数字,r表示不转义,+表示可匹配多个
    10     if number1.search(text)==None:
    11         return False
    12     number2=re.compile(r'[A-Z]+')#任意大写字母
    13     if number2.search(text)==None:
    14         return False
    15     number3 = re.compile(r'[a-z]+')  # 任意小写字母
    16     if number3.search(text) == None:
    17         return False
    18     return True
    19 # text=str(pyperclip.paste())#从剪贴板复制命令
    20 text=raw_input("Get the password that you want to set:
    ")
    21 if detection(text):
    22     print "The password is the strong password."
    23 else:
    24     print "Waring:the password is not the strong password!"

    运行结果

    示例1:

    示例2:

    示例3:

  • 相关阅读:
    webpack入门
    Javascript隐式转换
    一个最小手势库的实现
    运用JS设置cookie、读取cookie、删除cookie
    不同浏览器下兼容文本两端对齐
    使用CSS3实现一个3D相册
    JavaScript 火的有点过头了,但又能火多久呢?
    强大的css3
    CSS3与页面布局学习总结
    红米手机真机调试问题记录
  • 原文地址:https://www.cnblogs.com/heyangblog/p/11139822.html
Copyright © 2011-2022 走看看