Move password utils to utils::passwords module
This commit is contained in:
parent
ece3dbf71c
commit
4d85638d8c
8 changed files with 38 additions and 34 deletions
|
@ -58,7 +58,7 @@ pub fn parse_identity_proof(
|
|||
verify_minisign_signature(
|
||||
did_key,
|
||||
&message,
|
||||
&signature,
|
||||
signature,
|
||||
).map_err(|_| ValidationError("invalid identity proof"))?;
|
||||
},
|
||||
Did::Pkh(ref did_pkh) => {
|
||||
|
|
12
src/cli.rs
12
src/cli.rs
|
@ -28,12 +28,14 @@ use crate::models::users::queries::{
|
|||
set_user_password,
|
||||
};
|
||||
use crate::monero::wallet::create_monero_wallet;
|
||||
use crate::utils::crypto::{
|
||||
hash_password,
|
||||
generate_private_key,
|
||||
serialize_private_key,
|
||||
use crate::utils::{
|
||||
crypto::{
|
||||
generate_private_key,
|
||||
serialize_private_key,
|
||||
},
|
||||
files::remove_files,
|
||||
passwords::hash_password,
|
||||
};
|
||||
use crate::utils::files::remove_files;
|
||||
|
||||
/// Admin CLI tool
|
||||
#[derive(Parser)]
|
||||
|
|
|
@ -141,7 +141,7 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_get_json_signature_eip155() {
|
||||
fn test_get_json_signature_eip191() {
|
||||
let signed_object = json!({
|
||||
"type": "Test",
|
||||
"id": "https://example.org/objects/1",
|
||||
|
|
|
@ -71,15 +71,17 @@ use crate::models::users::queries::{
|
|||
get_user_by_did,
|
||||
};
|
||||
use crate::models::users::types::UserCreateData;
|
||||
use crate::utils::caip2::ChainId;
|
||||
use crate::utils::canonicalization::canonicalize_object;
|
||||
use crate::utils::crypto::{
|
||||
hash_password,
|
||||
generate_private_key,
|
||||
serialize_private_key,
|
||||
use crate::utils::{
|
||||
caip2::ChainId,
|
||||
canonicalization::canonicalize_object,
|
||||
crypto::{
|
||||
generate_private_key,
|
||||
serialize_private_key,
|
||||
},
|
||||
currencies::Currency,
|
||||
id::new_uuid,
|
||||
passwords::hash_password,
|
||||
};
|
||||
use crate::utils::currencies::Currency;
|
||||
use crate::utils::id::new_uuid;
|
||||
use super::helpers::get_relationship;
|
||||
use super::types::{
|
||||
Account,
|
||||
|
|
|
@ -10,8 +10,8 @@ use crate::models::users::queries::{
|
|||
get_user_by_name,
|
||||
get_user_by_login_address,
|
||||
};
|
||||
use crate::utils::crypto::verify_password;
|
||||
use crate::utils::currencies::{validate_wallet_address, Currency};
|
||||
use crate::utils::passwords::verify_password;
|
||||
use super::types::{TokenRequest, TokenResponse};
|
||||
use super::utils::generate_access_token;
|
||||
|
||||
|
|
|
@ -1,25 +1,7 @@
|
|||
use pem;
|
||||
use rand;
|
||||
use rand::prelude::*;
|
||||
use rsa::{Hash, PaddingScheme, PublicKey, RsaPrivateKey, RsaPublicKey};
|
||||
use rsa::pkcs8::{FromPrivateKey, FromPublicKey, ToPrivateKey, ToPublicKey};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
pub fn hash_password(password: &str) -> Result<String, argon2::Error> {
|
||||
let mut rng = rand::thread_rng();
|
||||
let salt: [u8; 32] = rng.gen();
|
||||
let config = argon2::Config::default();
|
||||
|
||||
argon2::hash_encoded(password.as_bytes(), &salt, &config)
|
||||
}
|
||||
|
||||
pub fn verify_password(
|
||||
password_hash: &str,
|
||||
password: &str,
|
||||
) -> Result<bool, argon2::Error> {
|
||||
argon2::verify_encoded(password_hash, password.as_bytes())
|
||||
}
|
||||
|
||||
pub fn generate_private_key() -> Result<RsaPrivateKey, rsa::errors::Error> {
|
||||
let mut rng = rand::rngs::OsRng;
|
||||
let bits = 2048;
|
||||
|
@ -28,6 +10,7 @@ pub fn generate_private_key() -> Result<RsaPrivateKey, rsa::errors::Error> {
|
|||
|
||||
#[cfg(test)]
|
||||
pub fn generate_weak_private_key() -> Result<RsaPrivateKey, rsa::errors::Error> {
|
||||
use rand::SeedableRng;
|
||||
let mut rng = rand::rngs::SmallRng::seed_from_u64(0);
|
||||
let bits = 512;
|
||||
RsaPrivateKey::new(&mut rng, bits)
|
||||
|
|
|
@ -6,4 +6,5 @@ pub mod files;
|
|||
pub mod html;
|
||||
pub mod id;
|
||||
pub mod markdown;
|
||||
pub mod passwords;
|
||||
pub mod urls;
|
||||
|
|
16
src/utils/passwords.rs
Normal file
16
src/utils/passwords.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
use rand::Rng;
|
||||
|
||||
pub fn hash_password(password: &str) -> Result<String, argon2::Error> {
|
||||
let mut rng = rand::thread_rng();
|
||||
let salt: [u8; 32] = rng.gen();
|
||||
let config = argon2::Config::default();
|
||||
|
||||
argon2::hash_encoded(password.as_bytes(), &salt, &config)
|
||||
}
|
||||
|
||||
pub fn verify_password(
|
||||
password_hash: &str,
|
||||
password: &str,
|
||||
) -> Result<bool, argon2::Error> {
|
||||
argon2::verify_encoded(password_hash, password.as_bytes())
|
||||
}
|
Loading…
Reference in a new issue