-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f87b343
commit 4bbf95d
Showing
7 changed files
with
4 additions
and
86 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,2 @@ | ||
//! Authentication protocol support. | ||
use md5::{Digest, Md5}; | ||
|
||
pub mod sasl; | ||
|
||
/// Hashes authentication information in a way suitable for use in response | ||
/// to an `AuthenticationMd5Password` message. | ||
/// | ||
/// The resulting string should be sent back to the database in a | ||
/// `PasswordMessage` message. | ||
#[inline] | ||
pub fn md5_hash(username: &[u8], password: &[u8], salt: [u8; 4]) -> String { | ||
let mut md5 = Md5::new(); | ||
md5.update(password); | ||
md5.update(username); | ||
let output = md5.finalize_reset(); | ||
md5.update(format!("{:x}", output)); | ||
md5.update(salt); | ||
format!("md5{:x}", md5.finalize()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn md5() { | ||
let username = b"md5_user"; | ||
let password = b"password"; | ||
let salt = [0x2a, 0x3d, 0x8f, 0xe0]; | ||
|
||
assert_eq!( | ||
md5_hash(username, password, salt), | ||
"md562af4dd09bbb41884907a838a3233294" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters