예제 #1
0
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 == '*****@*****.**').blend(
        User, email='*****@*****.**', password=generate_password_hash('pass'))
    mixer.guard(User.email == '*****@*****.**').blend(
        User, email='*****@*****.**', password=generate_password_hash('pass'), is_super=True)
예제 #2
0
    def process_formdata(self, valuelist):
        """Ensure that password is hashed."""
        super(PasswordField, self).process_formdata(valuelist)
        if self.data and not self.data.startswith("sha256$"):
            self.data = generate_password_hash(self.data)  # noqa

        if not self.data and self.object_data:
            self.data = self.object_data  # noqa
예제 #3
0
def test_generate_password_hash_sha256():
    from muffin.utils import generate_password_hash, check_password_hash

    password = '******'
    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)
예제 #4
0
def test_generate_password_hash_default():
    from muffin.utils import generate_password_hash, check_password_hash

    password = '******'
    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)
예제 #5
0
def test_generate_password_hash_sha256():
    from muffin.utils import generate_password_hash, check_password_hash

    password = '******'
    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)
예제 #6
0
def test_generate_password_hash_default():
    from muffin.utils import generate_password_hash, check_password_hash

    password = '******'
    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)
예제 #7
0
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': '******'})
    assert response.status_code == 302

    response = client.get('/')
    assert "Hello %s" % user.email 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')
    assert response.status_code == 302
예제 #8
0
 def generate_password(cls, raw_password):
     return generate_password_hash(raw_password)
예제 #9
0
 def set_password(self, password):
     self.password = generate_password_hash(password)
예제 #10
0
 def set_password(self, password):
     """Set an operator's password."""
     self.password = generate_password_hash(password)