def authenticate_user(username, password): result = User.view(get_db(), '_view/user/by_username', key=username) if len(result) == 0: raise InvalidUser('bad username') user = result.__iter__().next() if not hash_password(password, user.salt) == user.password: raise InvalidUser('bad password') return user
def register_post(self): try: form_result = RegisterForm().to_python(request.POST) user = User() user.username = form_result['username'] pwd, salt = gen_hash_password(form_result['password']) user.password = pwd user.salt = salt user.store(get_db()) c.title = 'Login' c.info_msgs.append('You are registered now.') return render('auth/login.mak') except formencode.Invalid, err: c.title = 'Register' html = render('auth/register.mak') return formencode.htmlfill.render(html, errors=err.error_dict)
def user_exists(username): result = User.view(get_db(), '_view/user/by_username', key=username) if len(result) == 0: return False return True