get back to where we were. but now with sea_orm and a more sane structure
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
11
neo-util/Cargo.toml
Normal file
11
neo-util/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "neo-util"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
argon2 = { version = "0.4", features = ["std"] }
|
||||
rand = { version = "0.8.5", features = ["std"] }
|
1
neo-util/src/lib.rs
Normal file
1
neo-util/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod password;
|
17
neo-util/src/password.rs
Normal file
17
neo-util/src/password.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use argon2::{password_hash::SaltString, Argon2, PasswordHash, PasswordHasher, PasswordVerifier};
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
pub fn hash_password(password: &str) -> anyhow::Result<String> {
|
||||
let argon2 = Argon2::default();
|
||||
let salt = SaltString::generate(OsRng);
|
||||
Ok(argon2
|
||||
.hash_password(password.as_bytes(), &salt)?
|
||||
.to_string())
|
||||
}
|
||||
|
||||
pub fn password_correct(password: &str, hash: &str) -> anyhow::Result<bool> {
|
||||
let password_hash = PasswordHash::new(hash)?;
|
||||
Ok(Argon2::default()
|
||||
.verify_password(password.as_bytes(), &password_hash)
|
||||
.is_ok())
|
||||
}
|
Reference in New Issue
Block a user