Skip to content

Commit 8c4bc67

Browse files
authored
Merge pull request #34 from sattamjh/master
safe_str_cmp deprecation
2 parents d2d4087 + 46cfbb2 commit 8c4bc67

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

guides/Flask-JWT Configuration Tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ jwt = JWT(app, authenticate, identity) # /auth
2626
And in our security.py file, we should have something like this:
2727

2828
```python
29-
from werkzeug.security import safe_str_cmp
29+
from hmac import compare_digest
3030
from models.user import UserModel
3131

3232
def authenticate(username, password):
3333
user = UserModel.find_by_username(username)
34-
if user and safe_str_cmp(user.password, password):
34+
if user and compare_digest(user.password, password):
3535
return user
3636

3737
def identity(payload):

section11/resources/user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from flask_restful import Resource, reqparse
2-
from werkzeug.security import safe_str_cmp
2+
from hmac import compare_digest
33
from flask_jwt_extended import (
44
create_access_token,
55
create_refresh_token,
@@ -43,7 +43,7 @@ def post(self):
4343

4444
user = UserModel.find_by_username(data['username'])
4545

46-
if user and safe_str_cmp(user.password, data['password']):
46+
if user and compare_digest(user.password, data['password']):
4747
access_token = create_access_token(identity=user.id, fresh=True)
4848
refresh_token = create_refresh_token(user.id)
4949
return {

section4/security.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from werkzeug.security import safe_str_cmp
1+
from hmac import compare_digest
22
from user import User
33

44
users = [
@@ -11,7 +11,7 @@
1111

1212
def authenticate(username, password):
1313
user = username_table.get(username, None)
14-
if user and safe_str_cmp(user.password, password):
14+
if user and compare_digest(user.password, password):
1515
return user
1616

1717
def identity(payload):

section5/security.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from werkzeug.security import safe_str_cmp
1+
from hmac import compare_digest
22
from user import User
33

44

55
def authenticate(username, password):
66
user = User.find_by_username(username)
7-
if user and safe_str_cmp(user.password, password):
7+
if user and compare_digest(user.password, password):
88
return user
99

1010

section6/security.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from werkzeug.security import safe_str_cmp
1+
from hmac import compare_digest
22
from models.user import UserModel
33

44

55
def authenticate(username, password):
66
user = UserModel.find_by_username(username)
7-
if user and safe_str_cmp(user.password, password):
7+
if user and compare_digest(user.password, password):
88
return user
99

1010

0 commit comments

Comments
 (0)