File tree Expand file tree Collapse file tree 5 files changed +15
-16
lines changed
Expand file tree Collapse file tree 5 files changed +15
-16
lines changed Original file line number Diff line number Diff line change 1919from __future__ import annotations
2020
2121import datetime
22- import hashlib
2322import logging
2423from typing import Any
2524from typing import Dict
@@ -64,11 +63,6 @@ class User(Model):
6463 confirmed_on = Field (datetime .datetime , fmt = "%Y-%m-%d %H:%M:%S" )
6564 previous_reset_token = Field (str )
6665
67- def check_password (self , password : str ) -> bool :
68- logging .debug ("Checking password again {} hashed password" .format (self .id ))
69- _hash , salt = self .password .split (":" )
70- return _hash == hashlib .sha3_512 (salt .encode () + password .encode ()).hexdigest ()
71-
7266 @staticmethod
7367 def create (
7468 first_name : str ,
Original file line number Diff line number Diff line change 3535from PyMatcha .utils .decorators import validate_params
3636from PyMatcha .utils .errors import NotFoundError
3737from PyMatcha .utils .errors import UnauthorizedError
38+ from PyMatcha .utils .password import check_password
3839from PyMatcha .utils .success import Success
3940from PyMatcha .utils .success import SuccessOutput
4041
41-
4242REQUIRED_KEYS_LOGIN = {"username" : str , "password" : str }
4343
4444auth_login_bp = Blueprint ("auth_login" , __name__ )
@@ -56,7 +56,7 @@ def auth_login():
5656 except NotFoundError :
5757 current_app .logger .debug ("/auth/login -> User not found" )
5858 raise UnauthorizedError ("Incorrect username or password" )
59- if not u . check_password (password ):
59+ if not check_password (u . password , password ):
6060 current_app .logger .debug ("/auth/login -> Password invalid" )
6161 raise UnauthorizedError ("Incorrect username or password" )
6262
Original file line number Diff line number Diff line change 3535from PyMatcha .utils .errors import UnauthorizedError
3636from PyMatcha .utils .mail import send_mail_html
3737from PyMatcha .utils .mail import send_mail_text
38+ from PyMatcha .utils .password import check_password
3839from PyMatcha .utils .success import Success
3940
4041profile_edit_bp = Blueprint ("profile_edit" , __name__ )
@@ -126,7 +127,7 @@ def edit_password():
126127 data = request .get_json ()
127128 old_password = data ["old_password" ]
128129 new_password = data ["new_password" ]
129- if not current_user . check_password (old_password ):
130+ if not check_password (current_user . password , old_password ):
130131 raise UnauthorizedError ("Incorrect password" )
131132 current_user .password = hash_password (new_password )
132133 current_user .save ()
Original file line number Diff line number Diff line change 1616 You should have received a copy of the GNU General Public License
1717 along with this program. If not, see <https://www.gnu.org/licenses/>.
1818"""
19- import hashlib
20- import logging
21- import uuid
19+ from argon2 import PasswordHasher
20+
21+ ph = PasswordHasher ()
2222
2323
2424def hash_password (password : str ) -> str :
25- salt = uuid .uuid4 ().hex
26- logging .debug ("Hashing password with salt {}" .format (salt ))
27- return hashlib .sha3_512 (salt .encode () + password .encode ()).hexdigest () + ":" + salt
25+ return ph .hash (password )
26+
27+
28+ def check_password (hash : str , password : str ) -> bool :
29+ return ph .verify (hash , password )
Original file line number Diff line number Diff line change @@ -27,4 +27,6 @@ pre-commit==2.5.1
2727names == 0.3.0
2828lorem == 0.1.1
2929future == 0.18.2
30- ip2geotools == 0.1.5
30+ ip2geotools == 0.1.5
31+
32+ argon2-cffi == 20.1.0
You can’t perform that action at this time.
0 commit comments