Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def Signup():
- while True:
- uname = input('Username: ')
- fname = uname + '.dat'
- if ' ' in uname:
- print('SPACE in username, pls try again!')
- continue
- else:
- if os.path.exists(fname):
- print(f'username {uname} already exists, pls try again!')
- continue
- else:
- # Username OK
- break
- while True:
- password = input('Password: ')
- confirm_password = input('Confirm Password: ')
- if password == confirm_password:
- # password OK
- break
- else:
- print('Passwords do not match, pls try again')
- continue
- # Saving password in username.dat file
- file = open(fname, 'w')
- file.write(password)
- file.close()
- print('Signup Successfully...')
- def Signin():
- while True:
- uname = input('Username: ')
- password = input('Password: ')
- fname = uname + '.dat'
- if os.path.exists(fname):
- # Username OK
- file = open(fname, 'r')
- password_in_file = file.read().rstrip() # to remove Enter key \n
- file.close()
- if password == password_in_file:
- print('Signin Successfully....')
- # Main Code here
- break
- else:
- print('Wrong password...')
- ans = input('Exit or Continue? (e\\c)')
- if ans == 'e':
- exit()
- else:
- continue
- else:
- print(f'Username {uname} does not exists, pls try again')
- continue
- # Program Start Here
- # Signup()
- Signin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement