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:

  • 相关阅读:
    c++ static_cast和dynamic_cast详解
    python 字符串格式化 format
    python zip() 函数
    零零散散的python笔记 2
    PAT 1017
    PAT 1016
    PAT 1015
    Jordan Lecture Note-8: The Sequential Minimal Optimization Algorithm (SMO).
    Jordan Lecture Note-7: Soft Margin SVM
    PAT 1014
  • 原文地址:https://www.cnblogs.com/heyangblog/p/11139822.html
Copyright © 2011-2022 走看看