I have 2 functions from separate scripts that communicate. What should happen is, if a value exists, a variable should be set to %username%; if the value doesn’t exist it should be set to “None”. If the variable is set to none, the function should continue and create a new account. If the variable is set to a username, the function should continue. So, why am I getting inconsistent, erratic results?
Functions as follow, they won’t run as they call other functions that aren’t included:
def database_get_user_details(user_database, username, detail):
value = "None"
rows = ((users_db_curs.execute("SELECT * FROM '" + user_database + "' WHERE username='" + username + "'"))).fetchall()
for row in rows:
if rows:
if detail == ("userID") : value = str(row[1])
elif detail == ("username") : value = str(row[2])
elif detail == ("password") : value = str(row[3])
elif detail == ("creator_exp"): value = str(row[4])
else : value = "None"
else:
value = "None"
return value
def game_register(username_table_name):
while True:
while True:
user_ID = raw_input("E-mail address: ")
if user_ID != "":
break
while True:
username = raw_input("Username : ")
if username != "":
break
while True:
password = raw_input("Password : ")
if password != "":
password = password.encode("hex")
break
usr = database_get_user_details(username_table_name, username, "username")
print usr
if (usr != "None") or (usr != None):
print usr
print "Username already taken!"
pause()
else:
database_create_user(username_table_name, user_ID, username, password, "250")
print "Successfully created %s with password: %s" %(username, password.decode("hex"))
pause()
break
Please note, I have not included the actual password encryption algorithm for security – I have just set it to encode to hex in this example.
Edit: Forgot to explain
It is almost as though I am calling random.choice(), I can’t find any consistency relating to whether or not the function creates a new user, or tells me that username has already been used.
Your code for existing users will always trigger because at least one of the inequalities will be true.
The condition should be