Python Password Prigram -


i creating password program programming class, requirements are:

8 characters/1 letter/1 digit/alphanumeric only

the problem .isalpha or .isdigit cancel each other out because require of string letters or numbers.

is there anyways can make check if atleast 1 character number or letter

############################### # prolog section # new_password.py # program check user's proposed # password. # (today's date goes here) # (programmer names go here) # (tester names go here) # possible future enhancements: # unresolved bugs: ###############################  ############################### # processing initialization section ############################### # code goes here minlength = 8 valid = false   ############################### # processing section # branching code: # looping code: ############################### # code goes here # user input password = str(input("type in password: "))     # test password length if len(password) >= minlength:     # test alphanumeric     if password.isalnum():         if password.isalpha():             if password.isdigit():         # if password meets both conditions, set valid true                 valid = true             else:                 #otherwise, give user meaningful error message                 print("error, password not contain number.")         else:             #otherwise, give user meaningful error message             print("error, password not contain letter.")     else:         # otherwise, give user meaningful error message         print("error, password not alphanumeric.") else:     # otherwise, give user meaningful error message     print("error, password less than",minlength,"characters.") ############################### # cleanup, termination, , exit  # section ############################### # code goes here # print informational messages # if password meets condition (at least 8 characters) if valid == true:     # print "successful" message     print("your new password valid.") else:     # otherwise, print "unsuccessful" message     print("your new password not valid.") 

use any():

valid = any(c.isalpha() c in password) , any(c.isdigit() c in password) 

this satisfy requirement there @ least 1 alpha character , 1 digit. combine password.isalnum() , length check , should able vet passwords.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -