-1

A password must have at least eight characters. • A password consists of only letters and digits. • A password must contain at least two digits

1

2 Answers 2

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()
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.