mercredi 21 octobre 2015

Check password validity (Python 3)

I am new to coding so please treat me as someone who knows nothing, and explanations with answers would be extremely appreciated

I am trying to write a program that checks a randomly generated password against a VERY strict criteria. I want the program to run nested so that it can generate a password and then check it against the criteria before printing the output to the user. The criteria is:

It must contain at least 1 uppercase, lowercase and 1 number, AND it must be between 7-14 characters in length and two characters of the same type may not appear side-by-side for example DD, ff, 33, etc. However they can be of different variations i.e. tT or hH etc.

I am also not allowed to use functions that may be commonly used by experts, I have to define my own function/s. This is what I have so far, but I am aware it may have many errors: (I am suffering mainly with the checkPass function, as I have managed to get the password generator working)

def checkPass(password):
    import random

    lower = random.randint(97, 122)
    upper = random.randint(65, 90)
    num = random.randint(0, 9)

    if lower and upper and num not in password and len(password) <7 or >14:
        return False
    else:
        return True

def randomPassword(number):
    import random

    for loop in range(number):
        password = ""
        checkPass(password)

        while checkPass is False:
            randLength = random.randint(7, 14)

            for n in range(randLength):

                lower = random.randint(97, 122)
                upper = random.randint(65, 90)
                num = random.randint(0, 9)

                randChoice = random.randint(1, 3)

                if randChoice == 1:
                    choice = chr(lower)
                elif randChoice == 2:
                    choice = chr(upper)
                else:
                    choice = str(num)
                    password += choice
                return password

            checkPass(password)

            print(password)

Thank you so much for those taking the time to look at my work and to help me, bless you all.




Aucun commentaire:

Enregistrer un commentaire