| 1 |
# Copyright 2013 Donald Stufft and individual contributors |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
import nacl.bindings |
| 16 |
|
| 17 |
_argon2_strbytes_plus_one = nacl.bindings.crypto_pwhash_STRBYTES |
| 18 |
|
| 19 |
PWHASH_SIZE = _argon2_strbytes_plus_one - 1 |
| 20 |
SALTBYTES = nacl.bindings.crypto_pwhash_SALTBYTES |
| 21 |
|
| 22 |
PASSWD_MIN = nacl.bindings.crypto_pwhash_PASSWD_MIN |
| 23 |
PASSWD_MAX = nacl.bindings.crypto_pwhash_PASSWD_MAX |
| 24 |
|
| 25 |
PWHASH_SIZE = _argon2_strbytes_plus_one - 1 |
| 26 |
|
| 27 |
BYTES_MAX = nacl.bindings.crypto_pwhash_BYTES_MAX |
| 28 |
BYTES_MIN = nacl.bindings.crypto_pwhash_BYTES_MIN |
| 29 |
|
| 30 |
ALG_ARGON2I13 = nacl.bindings.crypto_pwhash_ALG_ARGON2I13 |
| 31 |
ALG_ARGON2ID13 = nacl.bindings.crypto_pwhash_ALG_ARGON2ID13 |
| 32 |
ALG_ARGON2_DEFAULT = nacl.bindings.crypto_pwhash_ALG_DEFAULT |
| 33 |
|
| 34 |
|
| 35 |
def verify(password_hash: bytes, password: bytes) -> bool: |
| 36 |
""" |
| 37 |
Takes a modular crypt encoded argon2i or argon2id stored password hash |
| 38 |
and checks if the user provided password will hash to the same string |
| 39 |
when using the stored parameters |
| 40 |
|
| 41 |
:param password_hash: password hash serialized in modular crypt() format |
| 42 |
:type password_hash: bytes |
| 43 |
:param password: user provided password |
| 44 |
:type password: bytes |
| 45 |
:rtype: boolean |
| 46 |
|
| 47 |
.. versionadded:: 1.2 |
| 48 |
""" |
| 49 |
return nacl.bindings.crypto_pwhash_str_verify(password_hash, password) |