def test_encrypt_verify(self): test_passwd = 'test_password_1234' cipher = Auth.encrypt_passwd(test_passwd) self.assertTrue(Auth.verify_passwd(test_passwd, cipher)) self.assertFalse(Auth.verify_passwd('test_password_123', cipher))
def test_validate_valid_emails(self): valid = [ '*****@*****.**', '*****@*****.**', 244 * 'a' + '@google.com', # Max chars (255) 'abc123.+%%[email protected]', ] for email in valid: self.assertTrue(Auth.validate_email(email))
def test_validate_valid_usernames(self): valid = [ 'David', # Min chars (5) 'abcdeabcdeabcdeabcdeabcde', # Max chars (25) 's3662167', # Start with letter 'a__--013495-__-_9', # All allowed chars, end with number ] for uname in valid: self.assertTrue(Auth.validate_username(uname))
def test_validate_invalid_usernames(self): invalid = [ '5Davlid', # Starting with number 'asdf', # Lower than min chars (5) 'asdfasdfasdfasdfasdfasdfas', # Greater than max chars (25) 'aaaaaa;%a', # Contains invalid chars 'asdfasdf_', # Doesnt end with number/letter ] for uname in invalid: self.assertFalse(Auth.validate_username(uname))
def test_validate_invalid_emails(self): invalid = [ 'invalid@google@com', '[email protected]', 'invalid', 'invalid@something', 245 * 'a' + '@google.com', # Max chars (255) + 1 'invalid@gmail%.com' ] for email in invalid: self.assertFalse(Auth.validate_email(email))
def login(): if logged_in(session): return redirect('/admin') if request.method == 'GET' or 'ajax' not in request.form: form = LoginForm() return render_template('login.bs.html', form=form) if 'user' not in request.form or 'pass' not in request.form: return '{"auth_succes":false}' user = request.form['user'] pass_ = request.form['pass'] if not Auth.verify_passwd(pass_, app.config['ADMIN_PASSWORD']): return '{"auth_succes":false}' if user != app.config['ADMIN_USERNAME']: return '{"auth_success":false}' session['auth_success'] = True return '{"auth_success":true}'
# vim: set et sw=4 ts=4 sts=4: from config import CONFIG_RP from class_.Auth import Auth from class_.DBInterface import DBInterface from class_.Reception import Reception from class_.FaceRecognition import FaceRecognition dbi = DBInterface(CONFIG_RP['db']) auth = Auth(dbi) fr = FaceRecognition() reception_pi = Reception(config=CONFIG_RP, dbi=dbi, auth=auth, face_recognition=fr) reception_pi.start()
while True: pw = getpass('Password: '******'No password entered, exiting') exit() cf = getpass('Confirm') if pw != cf: print('Passwords do not match, please try again') continue #try: cipher = Auth.encrypt_passwd(pw) #except: # print('Invalid password format, please choose a different password') # continue break if cipher is None: print('Failed, please try again') exit() print('Do NOT store this in config.py') print('Store this in admin_webapp/instance/config.py') print('Restart after ensuring you have the following lines:\n') print('ADMIN_USERNAME = "******"') print('ADMIN_PASSWORD = "******"')