Skip to content

Commit d663441

Browse files
committed
Fixed MD5 check: "blank salt" doesn't mean "unsalted"
1 parent d8b1db0 commit d663441

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [0.2.4] - 2016-09-18
7+
8+
### Changed
9+
10+
- Fixed MD5 check: "blank salt" doesn't mean "unsalted".
11+
12+
613
## [0.2.3] - 2016-09-18
714

815
### Changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "djangohashers"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
authors = ["Ronaldo Racum <ronaldo@racum.com>"]
55
license = "BSD-3-Clause"
66
readme = "README.md"

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Add the dependency to your `Cargo.toml`:
1414

1515
```toml
1616
[dependencies]
17-
djangohashers = "0.2.3"
17+
djangohashers = "0.2.4"
1818
```
1919

2020
Reference and import:
@@ -39,7 +39,7 @@ Add the dependency to your `Cargo.toml` declaring the feature:
3939

4040
```toml
4141
[dependencies.djangohashers]
42-
version = "0.2.3"
42+
version = "0.2.4"
4343
features = ["fpbkdf2"]
4444
```
4545

@@ -178,6 +178,8 @@ let encoded = make_password_with_settings("KRONOS", "seasalt", Algorithm::PBKDF2
178178
// pbkdf2_sha1$24000$seasalt$F+kiWNHXbMBcwgxsvSKFCWHnZZ0=
179179
```
180180

181+
**Warning**: `make_password_with_settings` and `make_password_core` will both panic if salt is not only letters and numbers (`^[A-Za-z0-9]*$`).
182+
181183
### Generating a Hashed Password based on a Django version
182184

183185
> New in `0.2.1`.

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ pub enum Algorithm {
4343

4444
// Parses an encoded hash in order to detect the algorithm, returns it in an Option.
4545
fn identify_hasher(encoded: &str) -> Option<Algorithm> {
46-
if (encoded.len() == 32 && !encoded.contains("$")) ||
47-
(encoded.len() == 37 && encoded.starts_with("md5$$")) {
46+
if encoded.len() == 32 && !encoded.contains("$") {
4847
Some(Algorithm::UnsaltedMD5)
4948
} else if encoded.len() == 46 && encoded.starts_with("sha1$$") {
5049
Some(Algorithm::UnsaltedSHA1)
@@ -226,7 +225,7 @@ fn test_identify_hasher() {
226225
assert!(identify_hasher("7cf6409a82cd4c8b96a9ecf6ad679119")
227226
.unwrap() == Algorithm::UnsaltedMD5);
228227
assert!(identify_hasher("md5$$7cf6409a82cd4c8b96a9ecf6ad679119")
229-
.unwrap() ==Algorithm::UnsaltedMD5);
228+
.unwrap() == Algorithm::MD5);
230229
assert!(identify_hasher("sha1$$22e6217f026c7a395f0840c1ffbdb163072419e7")
231230
.unwrap() == Algorithm::UnsaltedSHA1);
232231
assert!(identify_hasher("bcrypt_sha256$$2b$12$LZSJchsWG/DrBy1erNs4eeYo6tZNlLFQmONdxN9HPesa1EyXVcTXK")

0 commit comments

Comments
 (0)