python file that saves passwords to txt
Ok, so this is in no way a secure way to do registration, or passwords. Have had a lot of family time so not much time to work on putting an explanation to this.
Basically the functions will test the file of users, to see if one exists already. Can't have users with the same name. Then if they are not on the list they can register, and add a name and password to a file. another function can test if that name and password are on the lines of the password txt. It also saves the name and password to a temporary list and dictionary for the session of the web app or whatever they are in. I took the list and dict. out, but they would be there for an implementation.
I imagine with a database, you would add the name and password to it, similarly.
Here's the code, I'll try and share more later.
Basically the functions will test the file of users, to see if one exists already. Can't have users with the same name. Then if they are not on the list they can register, and add a name and password to a file. another function can test if that name and password are on the lines of the password txt. It also saves the name and password to a temporary list and dictionary for the session of the web app or whatever they are in. I took the list and dict. out, but they would be there for an implementation.
I imagine with a database, you would add the name and password to it, similarly.
Here's the code, I'll try and share more later.
def search_users(name):
found = False
try:
with open('userNames.txt') as search:
for line in search:
line = line.rstrip()
if name in line:
found = True
print('found search users')
return found
finally:
print('finally')
def verify_password(name, password):
if search_users(name):
found = False
matches = name + password
print(matches)
try:
with open('passwords.txt') as search:
for line in search:
line = line.rstrip()
if matches in line:
found = True
print('found password')
return found
finally:
print('finally')
def create_user(name):
username.append(name)
try:
new_user = open("userNames.txt", 'a')
new_user.write(name + '\n')
finally:
new_user.close()
def create_password(name, password):
user_password[name] = password
try:
check_valid = open("passwords.txt", 'a')
check_valid.write(name + password + '\n')
finally:
check_valid.close()
Comments
Post a Comment