How to use the muffin.utils.generate_password_hash function in muffin

To help you get started, we’ve selected a few muffin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github klen / muffin / tests / test_utils.py View on Github external
def test_generate_password_hash_default():
    from muffin.utils import generate_password_hash, check_password_hash

    password = '#secret$'
    password_hash = generate_password_hash(password, digestmod='sha1', salt_length=8)

    assert password_hash.startswith('sha1')
    assert len(password_hash.split('$')[1]) == 8
    assert len(password_hash.split('$')[2]) == 40
    assert check_password_hash(password, password_hash)
github klen / muffin / tests / test_utils.py View on Github external
def test_generate_password_hash_sha256():
    from muffin.utils import generate_password_hash, check_password_hash

    password = '#secret$'
    password_hash = generate_password_hash(password, digestmod='sha256', salt_length=20)

    assert password_hash.startswith('sha256')
    assert len(password_hash.split('$')[1]) == 20
    assert len(password_hash.split('$')[2]) == 64
    assert check_password_hash(password, password_hash)
github klen / muffin / tests / test_example.py View on Github external
def test_login_logout(client, mixer):
    response = client.get('/')
    assert "Hello anonimous" in response.text

    from muffin.utils import generate_password_hash
    user = mixer.blend('example.models.User', password=generate_password_hash('pass'))
    response = client.post('/login', params={'email': user.email, 'password': 'pass'})
    assert response.status_code == 302

    response = client.get('/')
    assert "Hello %s" % user.username in response.text

    response = client.get('/profile')
    assert "%s profile here" % user.username in response.text

    response = client.get('/logout')
    assert response.status_code == 302

    response = client.get('/')
    assert "Hello anonimous" in response.text

    response = client.get('/profile')
github klen / muffin / example / migrations / 002_data.py View on Github external
> migrator.drop_columns(models, *names, cascade=True)
    > migrator.rename_column(model, old_name, new_name)
    > migrator.rename_table(model, new_name)
    > migrator.add_index(model, *columns, unique=False)
    > migrator.drop_index(model, index_name)
    > migrator.add_not_null(model, name)
    > migrator.drop_not_null(model, name)

    """
    from mixer.backend.peewee import Mixer
    from muffin.utils import generate_password_hash

    mixer = Mixer(commit=True)
    model = migrator.orm['user']
    mixer.blend(model, username='user', email='user@muffin.io',
                password=generate_password_hash('pass'))
github klen / muffin / example / manage.py View on Github external
def example_data():
    """ Create example users. """
    from mixer.backend.peewee import Mixer
    from muffin.utils import generate_password_hash
    from example.models import User

    mixer = Mixer(commit=True)
    mixer.guard(User.email == 'user@muffin.io').blend(
        User, email='user@muffin.io', password=generate_password_hash('pass'))
    mixer.guard(User.email == 'admin@muffin.io').blend(
        User, email='admin@muffin.io', password=generate_password_hash('pass'), is_super=True)
github klen / muffin / example / models.py View on Github external
def set_password(self, password):
        self.password = generate_password_hash(password)