Advertisement
Guest User

registration

a guest
Dec 29th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.35 KB | None | 0 0
  1. login = None
  2. choice = None
  3.  
  4.  
  5. class DBase(object):
  6.     def __init__(self, name):
  7.         self.file = open(name, 'a+')
  8.         self.file.seek(0)
  9.         if self.file.read() == '':
  10.             self.file.write('admin"admin"\n')
  11.  
  12.     def save(self, log, pas):
  13.         self.file.write(log + '"' + pas + '"\n')
  14.  
  15.     def control(self, log, pas=None):
  16.         self.file.seek(0)
  17.         for line in self.file:
  18.             line = line.split('"')[0]
  19.             if line == log and pas is None:
  20.                 return False
  21.         if pas is None:
  22.             return True
  23.         else:
  24.             self.file.seek(0)
  25.             for line in self.file:
  26.                 line = line.split('"')[1]
  27.                 if line == pas:
  28.                     return True
  29.  
  30.     def users(self):
  31.         all_users = []
  32.         print('\n')
  33.         self.file.seek(0)
  34.         for line in self.file:
  35.             line = line.split('"')[0]
  36.             all_users.append(line)
  37.             print(' ', line)
  38.         print('\nUsers: ', len(all_users), '\n')
  39.  
  40.     def close(self):
  41.         self.file.close()
  42.  
  43.  
  44. def log_on():
  45.     login = input('Login: ')
  46.     password = input('Password: ')
  47.  
  48.     if db.control(login, password):
  49.         return login
  50.     else:
  51.         input('User not found!')
  52.         login = 'Guest'
  53.         return login
  54.  
  55.  
  56. def log_out():
  57.     login = 'Guest'
  58.     return login
  59.  
  60.  
  61. def registration():
  62.     login = input('Login: ')
  63.     if db.control(login):
  64.         if control_login(login) is True:
  65.             password = input('Password: ')
  66.             while not control_pass(password):
  67.                 password = input('Password: ')
  68.             db.save(login, password)
  69.             input('Registration complete!')
  70.             return login
  71.     else:
  72.         input('This login not available')
  73.  
  74.  
  75. def control_login(login):
  76.     NOT_CORRECT = ' ,;"!?#$%^&*()+=\|/><№)'
  77.     if len(login) < 3 or len(login) > 12:
  78.         input('Please input more than 3 and less than 12 symbols.')
  79.     else:
  80.         for i in login:
  81.             if i in NOT_CORRECT:
  82.                 input('Please input correct login!\nNOT use follow symbols ,;"!?#$%^&*()+=\|/><№)')
  83.                 return False
  84.         return True
  85.  
  86.  
  87. def control_pass(password):
  88.     if len(password) < 6 or len(password) > 25:
  89.         input('Please input more than 6 and less than 25 symbols.')
  90.     elif ' ' in password:
  91.         input('Password not contain spaces')
  92.     else:
  93.         return True
  94.  
  95.  
  96. a = '1 - Log on'
  97. b = '1 - Log out'
  98. db = DBase('users.db')
  99.  
  100. while choice != '0':
  101.     if login is None:
  102.         login = 'Guest'
  103.     print('\n\tWelcome, %s!\n' % login)
  104.  
  105.     if login == 'Guest':
  106.         var = a
  107.         print(var)
  108.         print('2 - Registration')
  109.     elif login == 'admin':
  110.         print('\nWOW! Hello my Creator!\n')
  111.         var = b
  112.         print(var)
  113.     else:
  114.         print('\nSecret text for registration users!\n')
  115.         var = b
  116.         print(var)
  117.  
  118.     print('\n9 - Show users')
  119.     print('0 - Exit')
  120.  
  121.     choice = input('\nEnter you choice: ')
  122.     if choice == '1':
  123.         if login == 'Guest':
  124.             login = log_on()
  125.         else:
  126.             login = log_out()
  127.     elif choice == '2' and var == a:
  128.         login = registration()
  129.     elif choice == '9':
  130.         db.users()
  131.         input('\nBack')
  132.     elif choice == '0':
  133.         db.close()
  134.  
  135.  
  136. # &copy: alt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement