For fun, I have been making a very basic login system in Python. I was going to look up an algorithm or something for user info storage and transfer, but then decided it would be more fun to come up with and implement it myself. What I would like to know is:
Is there anyway to make it secure (i.e.-encrypting the password without revealing the algorithm in the file)?
Can the algorithm I used be made any more efficient?
Is it cleanly written? I tried to take into account the comments on my last question regarding simplifying code and any comments about its readability would be appreciated--by secondary goal is beautiful code.
#This program will do a couple of things.
#The first time it is run, it will request that you add a password. Once you do, it will change the check_e$
#Every subsequent time, it will check the password in the other file and then match user input.
#If user input is correct it will display a joke.
#If user input is incorrect it will exit the program.
#Function to help the user pick a password
def pick_password():
file = '/home/vhx/Documents/code/pydata_test/password_dbs/pswd.txt'
print 'Please pick a password.'
password = raw_input()
target = open(file, 'w')
target.write(password)
file = '/home/vhx/Documents/code/pydata_test/password_dbs/existence_check.txt'
target = open(file, 'w')
target.write('YES')
# file.close()
#Function to check the password with the password located in pswd.txt
def password_check():
file = '/home/vhx/Documents/code/pydata_test/password_dbs/pswd.txt'
pwd_check = open(file).read()
userpass = raw_input('Please input a password.\n')
if userpass == pwd_check:
print 'Password accepted!'
print 'Ready for the joke?'
raw_input()
print 'Why did the fly fly? Because the spider spied her!'
elif userpass != pwd_check:
print 'Sorry, wrong password.\n'
exit()
else:
print 'Invalid syntax.'
exit()
#location of password existence check file
EC = '/home/vhx/Documents/code/pydata_test/password_dbs/existence_check.txt'
PWD = '/home/vhx/Documents/code/pydata_test/password_dbs/pswd.txt' #Location of password file
pswd_exist = open(EC).read() #Checking to see if the password exists
if pswd_exist == 'YES':
pass
else:
pick_password() #If it doesn't, user will pick a password
#Checking for password
password_check()
Note: If you want to run it, it requires two files --pswd.txt
and existence_check.txt
--which you then must link (and replace all necessary file locations).
If you input the correct password, the program tells a joke, though whether its funny is debatable.