예제 #1
0
def authenticate_user_with_password(user_name, password):
	user = db.session.query(models.User).filter_by(user_name=user_name).first()
	if user:
		current_hash = str(user.password)
		salt = str(user.salt)
		hashed_password = app_utilities.hashed_password_with_salt(password, salt)
		if current_hash == hashed_password:
			return {'authorized' : True, 'user_id' : int(user.id)}
	return {'authorized' : False}
예제 #2
0
def register_user(form):
	user_name = form['user_name']
	password = form['password']
	email = form['email']
	first_name = form['first_name']
	last_name = form['last_name']
	salt = app_utilities.salt()
	hashed_password = app_utilities.hashed_password_with_salt(password, salt)
	try:
		user = models.User(
			user_name=user_name,
			password=hashed_password,
			salt=salt,
			email=email,
			first_name=first_name,
			last_name=last_name
			)
		db.session.add(user)
		db.session.commit()
		return {'registered' : True, 'user_id' : int(user.id)}
	except:
		{'registered' : False}