Advertisement
DrAungWinHtut

signup1.py

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