Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- login = None
- choice = None
- class DBase(object):
- def __init__(self, name):
- self.file = open(name, 'a+')
- self.file.seek(0)
- if self.file.read() == '':
- self.file.write('admin"admin"\n')
- def save(self, log, pas):
- self.file.write(log + '"' + pas + '"\n')
- def control(self, log, pas=None):
- self.file.seek(0)
- for line in self.file:
- line = line.split('"')[0]
- if line == log and pas is None:
- return False
- if pas is None:
- return True
- else:
- self.file.seek(0)
- for line in self.file:
- line = line.split('"')[1]
- if line == pas:
- return True
- def users(self):
- all_users = []
- print('\n')
- self.file.seek(0)
- for line in self.file:
- line = line.split('"')[0]
- all_users.append(line)
- print(' ', line)
- print('\nUsers: ', len(all_users), '\n')
- def close(self):
- self.file.close()
- def log_on():
- login = input('Login: ')
- password = input('Password: ')
- if db.control(login, password):
- return login
- else:
- input('User not found!')
- login = 'Guest'
- return login
- def log_out():
- login = 'Guest'
- return login
- def registration():
- login = input('Login: ')
- if db.control(login):
- if control_login(login) is True:
- password = input('Password: ')
- while not control_pass(password):
- password = input('Password: ')
- db.save(login, password)
- input('Registration complete!')
- return login
- else:
- input('This login not available')
- def control_login(login):
- NOT_CORRECT = ' ,;"!?#$%^&*()+=\|/><№)'
- if len(login) < 3 or len(login) > 12:
- input('Please input more than 3 and less than 12 symbols.')
- else:
- for i in login:
- if i in NOT_CORRECT:
- input('Please input correct login!\nNOT use follow symbols ,;"!?#$%^&*()+=\|/><№)')
- return False
- return True
- def control_pass(password):
- if len(password) < 6 or len(password) > 25:
- input('Please input more than 6 and less than 25 symbols.')
- elif ' ' in password:
- input('Password not contain spaces')
- else:
- return True
- a = '1 - Log on'
- b = '1 - Log out'
- db = DBase('users.db')
- while choice != '0':
- if login is None:
- login = 'Guest'
- print('\n\tWelcome, %s!\n' % login)
- if login == 'Guest':
- var = a
- print(var)
- print('2 - Registration')
- elif login == 'admin':
- print('\nWOW! Hello my Creator!\n')
- var = b
- print(var)
- else:
- print('\nSecret text for registration users!\n')
- var = b
- print(var)
- print('\n9 - Show users')
- print('0 - Exit')
- choice = input('\nEnter you choice: ')
- if choice == '1':
- if login == 'Guest':
- login = log_on()
- else:
- login = log_out()
- elif choice == '2' and var == a:
- login = registration()
- elif choice == '9':
- db.users()
- input('\nBack')
- elif choice == '0':
- db.close()
- # ©: alt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement