def create(): email = request.form['email'] phone = request.form['phone'] password = request.form['password'] password_confirmation = request.form['password_confirmation'] validator = CombinedValidator(validators=[ EmailValidator(lambda: email), PasswordValidator(lambda: password, lambda: password_confirmation), PhoneValidator(lambda: phone), UniqueEmailValidator(lambda: email) ]) errors, valid = validator.validate() if not valid: for e in errors: flash(e.message) return redirect(url_for('user.sign_up')) pu = PasswordUtil() user = User() user.email = email user.phone = phone user.salt = pu.generate_salt() user.password = pu.hash_password(password, user.salt) user.is_admin = False db.session.add(user) db.session.commit() flash('Możesz się teraz zalogować') return redirect(url_for('user.sign_in'))
def set_password(id): password = request.form["password"] password_confirmation = request.form["password_confirmation"] pv = PasswordValidator(lambda: password, lambda: password_confirmation) errors, valid = pv.validate() if not valid: for e in errors: flash(e.message) return redirect(url_for('user.get', id=id)) user = User.query.get(id) if user is None: abort(404) pu = PasswordUtil() salt = pu.generate_salt() sha = pu.hash_password(password, salt) user.salt = salt user.password = sha db.session.commit() flash('Zmieniono') return redirect(url_for('user.get', id=id))
def create(): if is_rest_call(request): username = request.json.get('username') password = request.json.get('password') password_confirmation = password pu = PasswordUtil() user = User() user.name = username user.salt = pu.generate_salt() user.password = pu.hash_password(password, user.salt) db.session.add(user) db.session.commit() return jsonify({'status': 'success'}), 200 username = request.form['username'] password = request.form['password'] password_confirmation = request.form['password_confirmation'] print(username) print(password) print(password_confirmation) validator = CombinedValidator(validators=[ PasswordValidator(lambda: password, lambda: password_confirmation), UniqueUsernameValidator(lambda: username) ]) errors, valid = validator.validate() if not valid: for e in errors: flash(e.message) return redirect(url_for('user.sign_up')) pu = PasswordUtil() user = User() user.name = username user.salt = pu.generate_salt() user.password = pu.hash_password(password, user.salt) db.session.add(user) db.session.commit() flash('Możesz się teraz zalogować') return redirect(url_for('user.sign_in'))
from app.pass_utils import PasswordUtil import random import datetime import dateutil import sys import logging logging.basicConfig() logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) fake = Factory.create('pl_PL') AMOUNT_OF_USERS = 50 AMOUNT_OF_MESSAGES = 180 AMOUNT_OF_OFFERS = 100 pu = PasswordUtil() app.db.session.commit() app.db.drop_all() app.db.create_all() for _ in range(AMOUNT_OF_USERS): user = User() user.email = fake.email() user.is_admin = False user.salt = pu.generate_salt() user.password = pu.hash_password(fake.password(), user.salt) user.phone = '123654789' app.db.session.add(user) print('.', end='')
from faker import Factory from app.pass_utils import PasswordUtil import random import datetime import dateutil import sys import logging logging.basicConfig() logging.getLogger('sqlalchemy.engine').setLevel(logging.ERROR) fake = Factory.create('pl_PL') AMOUNT_OF_USERS = 500 AMOUNT_OF_MEASUREMENTS = 45 pu = PasswordUtil() app.db.session.commit() app.db.drop_all() app.db.create_all() admin = User() admin.name = 'jaro' admin.salt = pu.generate_salt() admin.password = pu.hash_password('jaro', admin.salt) app.db.session.add(admin) app.db.session.commit() for _ in range(AMOUNT_OF_MEASUREMENTS): m = Measurement()
def sign_in_user(login, password): user = User.query.filter_by(email=login).first() if user is None: return False pu = PasswordUtil() hashed_password = pu.hash_password(password, user.salt) return hashed_password == user.password
import app from app.exceptions import BloodException from app.model.entities import User from app.pass_utils import PasswordUtil pu = PasswordUtil() def user_exists(username): users = User.query.filter_by(name=username).all() if len(users) > 0: return True return False def add_user(username, plain_password): if user_exists(username): raise BloodException("Użytkownik o takiej nazwie już istnieje") user = User() user.name = username user.salt = pu.generate_salt() user.password = pu.hash_password(plain_password, user.salt) app.db.session.add(user) app.db.session.commit() def valid_password(username, plain_password):