A password must have at least eight characters. • A password consists of only letters and digits. • A password must contain at least two digits
Asked
Active
Viewed 43 times
-1
-
3Does this answer your question? [Validation of a Password - Python](https://stackoverflow.com/questions/41117733/validation-of-a-password-python) – think-maths Feb 03 '21 at 05:03
2 Answers
1
you can refer to this code as your answer :
import re
def validate():
while True:
password = input("Enter a password: ")
if len(password) < 8:
print("Make sure your password is at lest 8 letters")
elif re.search('[0-9]',password) is None:
print("Make sure your password has a number in it")
elif re.search('[A-Z]',password) is None:
print("Make sure your password has a capital letter in it")
else:
print("Your password seems fine")
break
validate()

SPm
- 83
- 2
- 10
0
if you want to generate such passwords use this code:
import string
import random
letters =string.ascii_letters
digits = string.digits
comb = letters + digits
length = random.randint(6,98)
password = random.choices(digits,k = 2)
password+= random.choices(comb, k =length)
random.shuffle(password)
password = ''.join(password)
print(password)
I assumed the max length of a password is 100. you may want to change it.

Mahrad Hanaforoosh
- 521
- 3
- 11