How to display everything wrong with input for password tester - python

My program works perfectly fine but instead of returning EVERYTHING wrong with a password it will only return one problem back.
Example:
The password is ASD123 (the problems being less than 10 characters, and no symbols). The program only returns "The password is less than 10 characters"
passwordisokk = True
def passwordisOK():
while True:
passwordisokk = input("Please enter a password so we can validate:")
if len(passwordisokk) < 10:
print(" Your password should be 10 characters,please enter more characters")
passwordisokk = False
print(passwordisokk)
elif re.search("[0-9]",passwordisokk) is None:
print("Your password needs a number,please enter one")
passwordisokk = False
print(passwordisokk)
elif re.search("[A-Z]",passwordisokk) is None:
print(" Your password needs a capital letter,please enter one")
passwordisokk = False
print(passwordisokk)
elif re.search("[$,#,%,&,*]",passwordisokk) is None:
print(" You password needs one of these symbols:$,#,%,&,*. Please enter one")
passwordisokk = False
print(passwordisokk)
elif re.search("[ ]",passwordisokk):
passwordisokk = False
print("No spaces when entering your password please")
print(passwordisokk)
else:
passwordisokk = True
print(passwordisokk)
break
passwordisOK()

Just change the elif and else to if statements.
import re
passwordisokk = True
def checkPasswordisOK():
while True:
password = input("Please enter a password so we can validate:")
if len(password) < 10:
print(" Your password should be 10 characters,please enter more characters")
passwordisokk = False
print(passwordisokk)
if re.search("[0-9]",password) is None:
print("Your password needs a number,please enter one")
passwordisokk = False
print(passwordisokk)
if re.search("[A-Z]",password) is None:
print(" Your password needs a capital letter,please enter one")
passwordisokk = False
print(passwordisokk)
if re.search("[$,#,%,&,*]",password) is None:
print(" You password needs one of these symbols:$,#,%,&,*. Please enter one")
passwordisokk = False
print(passwordisokk)
if re.search("[ ]",password):
passwordisokk = False
print("No spaces when entering your password please")
print(passwordisokk)
if not passwordisokk:
passwordisokk = True
print(passwordisokk)
break
checkPasswordisOK()

Related

How do I condense a failed list of criteria with return False for the password validation?

def isValidPassword(password):
if (len(password)<=8):
print("Password must be at least 8 characters or more.")
return False
if any(digit.isdigit() for digit in password):
print("Password must have at least single digit or more.")
return False
if any(digit.isupper() for digit in password):
print("Password must have at least one uppercase letter or more.")
return False
if any(digit.islower() for digit in password):
print("Password must have at least one lowercase letter or more.")
return False
return True
def confirmedPassword():
isSecure = False ; isMatch = False
password = "" ; reenterPassword = ""
while(isSecure == False):
password = input("Enter your password: ")
isSecure = isValidPassword(password)
while(isMatch == False):
reenterPassword = input("\nPlease re-enter your password: ")
if (password == reenterPassword):
isMatch = True ; print("Password is confirmed. Thank you.")
print("The password you entered is approved and safe.")
else:
(password == reenterPassword)
isMatch = False ; print("Password is not confirmed. Please try again.")
confirmedPassword()
If anyone can please help. It is appreciated. I had a hard time figuring out how to condense a failed list of criteria printed out when I input "ABC" to run the program.
I changed your code to print out all the issues with the password before returning whether or not it is a valid password. I also fixed all of the if statements you had to correctly capture the password issue.
def isValidPassword(password):
valid = True
if (len(password) < 8):
print("Password must be at least 8 characters or more.")
valid = False
if not any(digit.isdigit() for digit in password):
print("Password must have at least single digit or more.")
valid = False
if not any(digit.isupper() for digit in password):
print("Password must have at least one uppercase letter or more.")
valid = False
if not any(digit.islower() for digit in password):
print("Password must have at least one lowercase letter or more.")
valid = False
return valid
def confirmedPassword():
isSecure = False ; isMatch = False
password = "" ; reenterPassword = ""
while(not isSecure):
password = input("Enter your password: ")
isSecure = isValidPassword(password)
while(not isMatch):
reenterPassword = input("\nPlease re-enter your password: ")
if (password == reenterPassword):
isMatch = True
print("Password is confirmed. Thank you.")
print("The password you entered is approved and safe.")
else:
isMatch = False
print("Password is not confirmed. Please try again.")
confirmedPassword()

Username and Password Variable Incorrect

Helo guys
i'm trying to create a login system, it's run normally when i input username and password directlt after i signed up on my own code, but when i try to login using false username or password bruteforcely variable "p" or "u" is changed by itself. I dunno why it's happened here's my code
sorry for my bad english and my bad code(it's weird"), i'm new in programming language and python "i've tried my best" so if anyone wants to fix my code or something else please help me, 1 more question is there any code to loop when the input is false? i used a function that call the lastest function if the input is false
import os
import sys
import re
def apus():
sys.stdout.write(CURSOR_UP_ONE)
sys.stdout.write(ERASE_LINE)
CURSOR_UP_ONE = '\x1b[1A'
ERASE_LINE = '\x1b[2K'
def main():
os.system("cls")
print(""""
Welcome To X Bank
Enter Any Key To Continue
""")
x = input()
menu()
def menu():
os.system('cls')
print("------------------------------------------------------------------------")
print('''
Don't Have An Account Yet? Please Sign Up
1. Login
2. Sign Up
''')
print("------------------------------------------------------------------------")
opsimenu()
def opsimenu():
#os.system("cls")
a = int(input())
os.system("cls")
if a == 1:
login()
elif a == 2:
signu()
else:
menu()
def ulog():
login()
def login():
os.system('cls')
print("Enter Your Username And Password \n \n")
C = input("Username = ")
D = input("Password = ")
while True:
if C == u and D == p:
login2()
break
else:
print("Your Username Or Password Is Incorrect")
ulog()
def login2():
os.system("cls")
print("Login Succesful")
def signu():
global Address
global Name
#print("\n ")
print("""
Your Username And Password *
*Must be at least 8 characters.
*must be between [a-z]
*Must be at least one alphabet should be of Upper Case [A-Z]
*Must be at least 1 number or digit between [0-9].
*Must be at least 1 character from [!##$%^&*].
""")
Name = str(input("Full Name:"))
Address = str(input("Address: "))
enteruser()
def signup():
enteruser()
def enteruser():
global u
Username = (input("Username:"))
flag = 0
while True:
if (len(Username) < 8):
flag = -1
break
elif not re.search("[a-z]", Username):
flag = -1
break
elif not re.search("[A-Z]", Username):
flag = -1
break
elif not re.search("[0-9]", Username):
flag = -1
break
elif not re.search("[!##$%^&*]", Username):
flag = -1
break
elif re.search("\s", Username):
flag = -1
break
else:
flag = 0
break
if flag == -1:
apus()
#print("Invalid Username")
signup()
u = Username
pw()
def ulangpw():
pw()
def pw():
global p
Password = str(input("Password:"))
while True:
if (len(Password) < 8):
flag = -1
break
elif not re.search("[a-z]", Password):
flag = -1
break
elif not re.search("[A-Z]", Password):
flag = -1
break
elif not re.search("[0-9]", Password):
flag = -1
break
elif not re.search("[!##$%^&*]", Password):
flag = -1
break
elif re.search("\s", Password):
flag = -1
break
else:
flag = 0
break
if flag == -1:
print("Invalid Password")
apus()
apus()
ulangpw()
p = Password
os.system("cls")
validating()
def validating():
print(" ---------------------------------------------------")
print(" You have successfully created your account.\n Press Any Key To Login. \n \n Validating Your Data")
print("\n • Full Name ="+ Name)
print(" • Address ="+ Address)
print(" • Username ="+ u)
print(" • Password ="+ p)
print(" ---------------------------------------------------")
#p = Password
confirm = str(input("\n Make sure all registration data that is filled in is correct> Y/N "))
while True:
if confirm == "Y" or confirm =="y":
login()
break
elif confirm == "N" or confirm == 'n':
os.system("cls")
signu()
break
else:
confirm = str(input("\n Make sure all registration data that is filled in is correct> Y/N ="))
break
>main()
python wont print this:
print("""
Your Username And Password *
*Must be at least 8 characters.
*must be between [a-z]
*Must be at least one alphabet should be of Upper Case [A-Z]
*Must be at least 1 number or digit between [0-9].
*Must be at least 1 character from [!##$%^&*].
""")
Because it is syntax for uncommenting text
""" multiline comment line 1
multiline comment line 2 """
You have to use quotes like
print("Hi Dad")

The simplest way to check for UPPERCASES

Here, I am trying to validate a password and check to see if there are capitals and numbers in the password before saving it as a different variable. Using functions, is it possible for me to do so. The indents have changed on the format, so please help me with other aspects.
def length(long):
while len(long) < 10:
print("Please make your password longer, up to at least 10 characters.")
print("Your password is only " + str(len(long) + " characters long")
if password.isupper() = True:
print("Welcome to this student interface")
username = input("Please enter a username")
password = input("Please enter a strong password")
length(password)
This is what I have now done:
def length(long):
bool LengthCheck = False
if len(long) < 10:
print("Please make your password longer, up to at least 10 characters.")
print("Your password is only " + str(len(long) + " characters long")
else:
LengthCheck = True
errors = []
print("Welcome to this student interface")
username = input("Please enter a username")
password = input("Please enter a strong password")
length(password)
bool Capcheck = False
bool DigCheck = False
while CapCheck = False or CapCheck = False:
length(password)
if not any(x.isupper() for x in password):
errors.append("Your password needs at least 1 capital.")
else:
CapCheck = True
break
if not any(x.islower() for x in password):
errors.append("......... Why?")
if not any(x.isdigit() for x in password):
errors.append("You need to have at least 1 digit")
else:
DigCheck = True
break
if errors:
print(" ".join(errors))
password = input("Please enter a stronger password")
Apparently there is an error with my boolean here, please help
def length(long):
bool LengthCheck = False
if len(long) < 10:
print("Please make your password longer, up to at least 10 characters.")
print("Your password is only " + str(len(long) + " characters long")
else:
LengthCheck = True
Try using islower():
password.islower()
This returns True if there are no Uppercases in the password.
Now if you want to check if it has number i it, you have to follow #jubnvz:
any(i.isdigit() for i in password)
or a more specific way:
any(map(str.isdigit, password))
And for your password entries, try:
while True:
password = input(""Please enter a strong password:")
if not any(x.isupper() for x in password):
print("Your password needs at least 1 upper case.")
elif not any(x.isdigit() for x in password):
print("You need to have at least 1 digit")
elif not any(x.islower() for x in password):
print("Your password needs at least 1 lower case.")
elif len(password) < 10:
print("Please make your password longer, up to at least 10 characters.")
print("Your password is only " + str(len(password)) + " characters long")
else:
break
If you want to and a confirm password too, try:
while True:
password = input(""Please enter a strong password:")
if not any(x.isupper() for x in password):
print("Your password needs at least 1 upper case.")
elif not any(x.isdigit() for x in password):
print("You need to have at least 1 digit")
elif not any(x.islower() for x in password):
print("Your password needs at least 1 lower case.")
elif len(password) < 10:
print("Please make your password longer, up to at least 10 characters.")
print("Your password is only " + str(len(password)) + " characters long")
else:
passwordcon = input(""Please confirm your password:")
if passwordcon == password:
break
else:
print("Your passwords do not match, try again'")
any([p.isupper() for p in password])

Error with referenced before assignment in python

I am trying to create a login and register program in simple console python, however when trying to make a loop that will check if the username contains a digit I keep getting the error, ("UnboundLocalError: local variable 'includesDigit' referenced before assignment") the code is:
def register():
incluesDigit = False
print("")
print("Create Account")
print("~~~~~~~~~~~~~~")
print("Username: ")
registerUsername = input("")
for char in registerUsername:
if char.isdigit():
includesDigit = True
if includesDigit == True:
print("Please enter a username that does not contain a number")
register()
print("Password: ")
registerPassword = input("")
if len(registerPassword) < 5:
print("Please enter a password that is atleast 5 characters")
register()
if len(registerPassword) > 15:
print("Please enter a password that is less than or fifteen character")
logCreate = open("C:\\Desktop\\Login Program\\Accounts\\" + registerUsername + ".txt", "w")
logCreate.write(registerPassword)
logCreate.close()
login()
There is a typo in line 2.
incluesDigit = False
Should be
includesDigit = False

When password doesn't comply with if statements doesn't return back to raw_input

Function check whether user's password qualifies, as far as alphanumeric characters, 10 characters length min, and lower and uppercase characters.
def is_good_password(password):
count_upper, count_lower = 0, 0
for characters in password:
if characters.isupper():
count_upper += 1
if characters.islower():
count_lower += 1
is_password_good = True
if len(password) <= 10:
print "Password Is Too Weak, Must Be More Than 10 Characters Long!"
is_password_good = False
if set(database).intersection(password):
print "Password Must Contain Alphanumeric Characters!"
is_password_good = False
if count_upper < 1 or count_lower < 1:
print "Password Must Contain at Least One Uppercase and One Lowercase Character!"
is_password_good = False
create_user(database)
print "Welcome! Username & Password Successfully Created!"
return is_password_good
I want the create_user() function raw_input for passcode to return back to passcode if the user's password doesn't qualify on the above function; however, the create_user() function returns the passcode raw_input back to the user raw_input if the password doesn't work.
How can I fix this?
Thanks
def create_user(database):
good_user = False
good_pass = False
while not good_user or not good_pass:
user = raw_input("Enter a New Username: ")
good_user = is_good_user(user)
passcode = raw_input("Enter a New Password: ")
good_pass = is_good_password(passcode)
database[user] = passcode
dump_data()
Just add another loop; you don't need to use flag variables either, just use break to end the loop when you have a good user or password:
while True:
user = raw_input("Enter a New Username: ")
if is_good_user(user):
break
print "That's not a good username, please try again"
while True:
passcode = raw_input("Enter a New Password: ")
if is_good_password(passcode):
break
print "That's not a good password, please try again"
database[user] = passcode
dump_data()
Did I understand you correctly?
def create_user(database):
good_user = False
good_pass = False
while not good_user:
user = raw_input("Enter a New Username: ")
good_user = is_good_user(user)
while not good_pass:
passcode = raw_input("Enter a New Password: ")
good_pass = is_good_password(passcode)
database[user] = passcode
dump_data()

Categories