mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
User: use aurweb.config options.salt_rounds
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
d8556b0d86
commit
cec07c76b6
2 changed files with 14 additions and 4 deletions
|
@ -44,5 +44,5 @@ def getboolean(section, option):
|
|||
return _get_parser().getboolean(section, option)
|
||||
|
||||
|
||||
def getint(section, option):
|
||||
return _get_parser().getint(section, option)
|
||||
def getint(section, option, fallback=None):
|
||||
return _get_parser().getint(section, option, fallback=fallback)
|
||||
|
|
|
@ -15,6 +15,8 @@ import aurweb.schema
|
|||
from aurweb.models.ban import is_banned
|
||||
from aurweb.models.declarative import Base
|
||||
|
||||
SALT_ROUNDS_DEFAULT = 12
|
||||
|
||||
|
||||
class User(Base):
|
||||
""" An ORM model of a single Users record. """
|
||||
|
@ -39,16 +41,24 @@ class User(Base):
|
|||
authenticated = False
|
||||
nonce = None
|
||||
|
||||
# Make this static to the class just in case SQLAlchemy ever
|
||||
# does something to bypass our constructor.
|
||||
salt_rounds = aurweb.config.getint("options", "salt_rounds",
|
||||
SALT_ROUNDS_DEFAULT)
|
||||
|
||||
def __init__(self, Passwd: str = str(), **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
# Run this again in the constructor in case we rehashed config.
|
||||
self.salt_rounds = aurweb.config.getint("options", "salt_rounds",
|
||||
SALT_ROUNDS_DEFAULT)
|
||||
if Passwd:
|
||||
self.update_password(Passwd)
|
||||
|
||||
def update_password(self, password, salt_rounds=12):
|
||||
def update_password(self, password):
|
||||
self.Passwd = bcrypt.hashpw(
|
||||
password.encode(),
|
||||
bcrypt.gensalt(rounds=salt_rounds)).decode()
|
||||
bcrypt.gensalt(rounds=self.salt_rounds)).decode()
|
||||
|
||||
@staticmethod
|
||||
def minimum_passwd_length():
|
||||
|
|
Loading…
Add table
Reference in a new issue