Advertisement
DrAungWinHtut

signup.py

May 28th, 2023
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. import os
  2.  
  3.  
  4. def Signup():
  5.     print('===Signup===\n')
  6.  
  7.     # To Ask and check username, if exists ask again
  8.     while True:
  9.         uname = input('Username: ')
  10.         fname = uname + '.dat'
  11.         if not ' ' in uname:
  12.             if os.path.exists(fname):
  13.                 print('User already exists, pls try another Username!')
  14.                 continue
  15.  
  16.             else:
  17.                 break
  18.         else:
  19.             print('SPACE in Username, please try again!')
  20.             continue
  21.  
  22.     # To Ask password and check it
  23.     while True:
  24.         password = input('Password: ')
  25.         confirm_password = input('Confirm Password: ')
  26.         if password == confirm_password:
  27.             break
  28.         else:
  29.             print('Passwords do not match, pls try again!')
  30.  
  31.     # Open file and Save password
  32.     file = open(fname, 'w')
  33.     file.write(password)
  34.     file.close()
  35.     print(f'Signup user {uname} Successfully')
  36.  
  37.  
  38. def Signin():
  39.     print('===Signin===\n')
  40.     uname = input('Username: ')
  41.     password = input('Password: ')
  42.     fname = uname + '.dat'
  43.  
  44.     # check if username is OK
  45.     if not os.path.exists(fname):
  46.         print(f'Username {uname} does not exists')
  47.         ans = input('Signup? (y\\n): ')
  48.         if ans.lower() == 'y':
  49.             Signup()
  50.         else:
  51.             exit()
  52.     # check if password is OK
  53.     else:
  54.         file = open(fname, 'r')
  55.         password_in_file = file.read().rstrip()
  56.         file.close()
  57.         if password == password_in_file:
  58.             print('Signin Successfully...')
  59.             # Call fun from here
  60.         else:
  61.             print('wrong password,exiting...')
  62.  
  63.  
  64. # Program Start Here
  65. if __name__ == '__main__':
  66.     Signin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement