Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using secure passwords is extremely important, given that many of us store impor

ID: 3850155 • Letter: U

Question

Using secure passwords is extremely important, given that many of us store important information online. Write a function that accepts a password as a parameter and validates it, according to these rules:

At least eight characters long

Includes at least one uppercase and one lowercase letter

Includes at least one digit

Write a Python program that uses this function to check passwords. The program should prompt the user for a password and then check to ensure that it conforms to the rules. If a password does not meet the requirements above, the program should prompt again until it does.

Explanation / Answer

Python 2.7 code:

def isvalid(password):
   if(len(password) < 8):
       return False
   small_letter = False
   big_letter = False
   digit = False
   for i in range(0,len(password)):
       if( ord(password[i]) <= 122 and ord(password[i]) >= 97):
           small_letter = True
           break;
   if(small_letter == False):
       return False
   for i in range(0,len(password)):
       if( ord(password[i]) <= 90 and ord(password[i]) >= 65):
           big_letter = True
           break;
   if(big_letter == False):
       return False
   for i in range(0,len(password)):
       if( ord(password[i]) <= 57 and ord(password[i]) >= 48):
           digit = True
           break;
   if(digit == False):
       return False
   else:
       return True
      
while(True):
   print "Enter a new password!"
   password = raw_input().strip()
   if(isvalid(password)):
       print password, "is a valid password!"
       break;
   else:
       print password, "is a invalid password!"  

Sample Output:

Enter a new password!
akash1234
akash1234 is a invalid password!
Enter a new password!
Akashasdf
Akashasdf is a invalid password!
Enter a new password!
AKASH1234
AKASH1234 is a invalid password!
Enter a new password!
Akash1234
Akash1234 is a valid password!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote