0

The program asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a function that checks whether a password is valid.

What do I need to add in order to make the program ask the user like the instruction above? Help pls

    enter def isValid(password):
    if (len(password) < 8 or len(password) > 15):
        return False
    arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    for i in password:
        if i in arr:
            count = 1
            break
    if count == 0:
        return False
    for i in range(65, 91):
        if chr(i) in password:
            count = 1
    if (count == 0):
        return False
    if (True):
        count = 0
    for i in range(90, 123):
        if chr(i) in password:
            count = 1
    if(count == 0):
        return False
    return True
password1 = "mDampac1999"
if (isValid([i for i in password1])):
    print("Corect Password")
else:
    print("Invalid Password")
password2 = "Astayuno1738"
if (isValid([i for i in password2])):
    print("Correct Password")
else:
    print("Invalid Password")code here
Idan Gaming
  • 5
  • 1
  • 4
  • Does this answer your question? [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – MisterMiyagi Oct 17 '20 at 10:47
  • Note that you can ``return`` from inside a loop. There is no need to drag along and reset ``count`` to delay rejection beyond the end of a loop. – MisterMiyagi Oct 17 '20 at 10:49
  • 1
    You can use `.isnumeric()` on strings (like the `input()` method return value) to check if it's a valid number – Banana Oct 17 '20 at 10:49
  • No good sir. I need a code where it prompts the user to enter a password and if the password is correct, it confirms it. If the user enters a wrong password, it asks again. – Idan Gaming Oct 17 '20 at 10:50
  • As of the moment the code would just validate the "mDampac" and "astayuno" password – Idan Gaming Oct 17 '20 at 10:51
  • Can you clarify what your first comment was directed at? If it was directed at the first comment, "ask for input repeatedly (at most twice) until correct (as a password)" seems to be a textbook subset of "ask for input repeatedly until correct". – MisterMiyagi Oct 17 '20 at 10:55

1 Answers1

1

You can check if they are same and assign condition's result to a variable. Also in Python, you can check if strings are equals using == operator

same = False
while not same:
    password = input("Enter password: ")
    confirm_password = input("Enter password again: ")

    same = password == confirm_password