Ejemplo n.º 1
0
class TestHasher(TestCase):
    def setUp(self):
        self.app = Flask(__name__)
        self.pw = PasswordHasher(self.app)

    def test_default_algorithm(self):
        self.assertEqual(self.pw.algorithm, 'pbkdf2')

    def test_hash_password(self):
        hashed_password1 = self.pw.hash_password('password')
        hashed_password2 = self.pw.hash_password('password')
        self.assertNotEqual(hashed_password1, hashed_password2)

    def test_check_hash(self):
        hashed_password = self.pw.hash_password('password')

        self.assertTrue(self.pw.check_password('password', hashed_password))
        self.assertFalse(self.pw.check_password('wrong', hashed_password))
Ejemplo n.º 2
0
from flask import Flask
from flask_password import PasswordHasher


class Config(object):
    PASSWORD_ALGORITHM = 'pbkdf2'
    PBKDF2_ITERATIONS = 50000

app = Flask(__name__)
app.debug = True
app.config.from_object(Config())

pw = PasswordHasher()
pw.init_app(app)

hashed_password = pw.hash_password('my password')

print(hashed_password)
Ejemplo n.º 3
0
 def test_algorithm(self):
     hashed_password = self.pw.hash_password('password', self.pw.salt())
     self.assertEqual(MD5PasswordHasher.algorithm, PasswordHasher.get_algorithm(hashed_password))
Ejemplo n.º 4
0
from flask import Flask
from flask import request
from flask import render_template
from flask import Response
from flask_password import PasswordHasher

app = Flask(__name__)
app.debug = True

pw = PasswordHasher()
pw.init_app(app)

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'GET':
        return Response(render_template('hashing_example.html'))

    password = request.form.get('password')
    algorithm = request.form.get('algorithm')
    hashed_password = pw.hash_password(password, algorithm=algorithm)

    return Response(render_template('hashing_example.html',
                                    hashed_password=hashed_password,
                                    hashed_password_length=len(hashed_password)))

if __name__ == '__main__':
    app.run()
Ejemplo n.º 5
0
 def setUp(self):
     self.app = Flask(__name__)
     self.pw = PasswordHasher(self.app)
from flask import Flask
from flask_password import PasswordHasher


class Config(object):
    PASSWORD_ALGORITHM = 'bcrypt'
    BCRYPT_ROUNDS = 14

app = Flask(__name__)
app.debug = True
app.config.from_object(Config())

pw = PasswordHasher()
pw.init_app(app)

hashed_password = pw.hash_password('my password')

print(hashed_password)
Ejemplo n.º 7
0
 def test_algorithm(self):
     hashed_password = self.pw.hash_password('password', self.pw.salt())
     self.assertEqual(MD5PasswordHasher.algorithm,
                      PasswordHasher.get_algorithm(hashed_password))