Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def Signup():
- print('===Signup===\n')
- # To Ask and check username, if exists ask again
- while True:
- uname = input('Username: ')
- fname = uname + '.dat'
- if not ' ' in uname:
- if os.path.exists(fname):
- print('User already exists, pls try another Username!')
- continue
- else:
- break
- else:
- print('SPACE in Username, please try again!')
- continue
- # To Ask password and check it
- while True:
- password = input('Password: ')
- confirm_password = input('Confirm Password: ')
- if password == confirm_password:
- break
- else:
- print('Passwords do not match, pls try again!')
- # Open file and Save password
- file = open(fname, 'w')
- file.write(password)
- file.close()
- print(f'Signup user {uname} Successfully')
- def Signin():
- print('===Signin===\n')
- uname = input('Username: ')
- password = input('Password: ')
- fname = uname + '.dat'
- # check if username is OK
- if not os.path.exists(fname):
- print(f'Username {uname} does not exists')
- ans = input('Signup? (y\\n): ')
- if ans.lower() == 'y':
- Signup()
- else:
- exit()
- # check if password is OK
- else:
- file = open(fname, 'r')
- password_in_file = file.read().rstrip()
- file.close()
- if password == password_in_file:
- print('Signin Successfully...')
- # Call fun from here
- else:
- print('wrong password,exiting...')
- # Program Start Here
- if __name__ == '__main__':
- Signin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement