Esempio n. 1
0
    def __init__(self, *args, password, passhash=None, **kwargs):
        """
        Creates a new `User` object. The given password will be hashed automatically.

        The `passhash` parameter specifies an already hashed password, and can
        be used to speed up tests, as bcrypt is intentionally slow.
        """
        pwd = None
        if passhash is not None: pwd = passhash
        else: pwd = bcrypt.generate_password_hash(password)
        super(User, self).__init__(*args, password=pwd, **kwargs)
Esempio n. 2
0
def sample_passwds():
    """Pre-generates password hashes for `sample_users`. This drastically speeds up any tests
    relying on sample users, as bcrypt is intentionally very slow."""
    pwds = dict(
        admin='a',
        mod='b',
        arch='c',
        user='******',
    )
    for k, pwd in pwds.items():
        pwds[k] = dict(password=pwd,
                       passhash=bcrypt.generate_password_hash(pwd))
    return pwds
Esempio n. 3
0
def sample_passwds():
    """Pre-generates password hashes for `sample_users`. This drastically speeds up any tests
    relying on sample users, as bcrypt is intentionally very slow."""
    pwds = {
        'admin': 'a',
        'mod': 'b',
        'arch': 'c',
        'user': '******',
        '2fa': 'e',
    }
    for k, pwd in pwds.items():
        pwds[k] = dict(password=pwd,
                       passhash=bcrypt.generate_password_hash(pwd))
    return pwds
Esempio n. 4
0
 def set_password(self, password):
     """Sets a new password. The given password will be hashed."""
     self.password = bcrypt.generate_password_hash(password)