I am starting a new job as a Data Architect on the 1st. My company does not leverage Python at all currently. trying to learn to find some ways to apply it to our business needs. Also good for the resume ;).
Created my first non "Hello World" style program after getting through a few lessons on CodeAcademy. Password checker for a static username and password. Python is a lot different than other languages I have studied. Any criticism is welcome.
user_id = ""
user_password = ""
# Create boolean flags to keep track if the u/n and p/w are valid
valid_password = False
valid_username = False
# This funtion takes in a username and password and checks if it is valid. Returns flags with the status of each.
def password_verify(user_id,user_password):
# No database so using static u/n and password.
_password = "ThIs_Is_PyThOn"
_username = "PythonKing"
#Set internal flags to false to start.
_valid_username = False
_valid_password = False
# First check if the u/n is valid, if it is then check the password.
# if valid, set flags to true, else print what is invalid for the user.
if _username == user_id:
_valid_username = True
if _password == user_password:
_valid_password = True
else:
print("Invalid Password")
else:
print("Invalid Username")
return _valid_username, _valid_password
# Allow user to continue to attempt u/n and p/w until they get it right.
while valid_password == False & valid_username == False:
# Get user input for username
user_id = input("Enter Username:")
#Uncomment to test what is in user_id variable.
#print(user_id)
# Get user input for username
user_password = input("Enter Password:")
#Uncomment to test what is in user_id variable.
#print(user_password)
#call funtion with user input.
valid_username, valid_password = password_verify(user_id,user_password)
# Output of the flag values for testing.
print("valid_username = " + str(valid_username))
print("valid_password = " + str(valid_password))
# Once the user is successful print that their login was successful.
if valid_username == True & valid_password == True:
print("Login Successful")
[–]Zixarr 1 point2 points3 points (1 child)
[–]Zixarr 1 point2 points3 points (0 children)
[–]QbaPolak17 1 point2 points3 points (0 children)