Skip to content
Snippets Groups Projects
Commit 3198c8c2410c authored by Alex Gaynor's avatar Alex Gaynor
Browse files

fixes #416 -- correctly handle invalid salts (#417)

parent eb566079b8ea
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,9 @@
.try_into()
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?;
let hashed = py.allow_threads(|| bcrypt::hash_with_salt(password, cost, raw_salt).unwrap());
let hashed = py
.allow_threads(|| bcrypt::hash_with_salt(password, cost, raw_salt))
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?;
Ok(pyo3::types::PyBytes::new(
py,
hashed.format_for_version(version).as_bytes(),
......
......@@ -272,6 +272,11 @@
b"badpass",
b"$2b$04$?Siw3Nv3Q/gTOIPetAyPr.GNj3aO0lb1E5E9UumYGKjP9BYqlNWJe",
)
with pytest.raises(ValueError):
bcrypt.checkpw(
b"password",
b"$2b$3$mdEQPMOtfPX.WGZNXgF66OhmBlOGKEd66SQ7DyJPGucYYmvTJYviy",
)
def test_checkpw_str_password():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment