python作业题 验证密码有效的机器

作为一个拍森的爱好者,虽然平时工作忙也要按时写作业。

Password validator is a program that validates passwords to match specific rules. For example, the minimum length of the password must be eight characters long and it should have at least one uppercase letter in it. 

A valid password is the one that conforms to the following rules:
 - Minimum length is 5;
 - Maximum length is 10;
 - Should contain at least one number;
 - Should contain at least one special character (such as &, +, @, $, #, %, etc.);
 - Should not contain spaces.

Examples:
Input: "Sololearn"
Output: false

Input: "John Doe"
Output: false

Input: "$ololearn7"
Output: true

Write a program to checks if the user input is a valid password or not.

密码验证要求:

  1. 至少一个数字
  2. 至少一个特殊符号(除空格以外的符号比如=/>之类
  3. 长度在5到10位(均可以包含)
  4. 不能有空格
闭锁条件
必要条件

找出闭锁条件(长度不符,空格立即break)在没有的情况下找到必要条件(特殊符号,数字)

def xx(a):
	import re
	s=re.search(r'[^a-z0-9A-Z\s]',a)
	sp,le,nu=0,0,0
	if s:
		for i in a:
			if i.isspace():
				print('no space')
				sp+=1
				break
			elif len(a) not in range(5,11):
				print('illegal length')
				le+=1
				break
			elif i.isnumeric() and nu==0:
				nu+=1
				continue
		if sp==0 and le==0 and nu==1:
			print('legal password')
	else:
		print('at least one sp')
xx('jjjj*jas6f6')

你可能感兴趣的:(笔记)