mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 17:12:22 +00:00
Remove unnecessary pwhash command
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
use argon2::password_hash::SaltString;
|
||||
use clap::{Parser, ValueEnum};
|
||||
use password_hash::{PasswordHasher, rand_core::OsRng};
|
||||
use pbkdf2::Params;
|
||||
use rustical_frontend::FrontendConfig;
|
||||
|
||||
use crate::config::{
|
||||
Config, DataStoreConfig, DavPushConfig, HttpConfig, SqliteDataStoreConfig, TracingConfig,
|
||||
};
|
||||
use clap::Parser;
|
||||
use rustical_frontend::FrontendConfig;
|
||||
|
||||
mod membership;
|
||||
pub mod principals;
|
||||
@@ -33,49 +29,3 @@ pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
|
||||
println!("{generated_config}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, ValueEnum)]
|
||||
enum PwhashAlgorithm {
|
||||
#[value(help = "Use this for your password")]
|
||||
Argon2,
|
||||
#[value(help = "Significantly faster algorithm, use for app tokens")]
|
||||
Pbkdf2,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct PwhashArgs {
|
||||
#[arg(long, short = 'a')]
|
||||
algorithm: PwhashAlgorithm,
|
||||
#[arg(
|
||||
long,
|
||||
short = 'r',
|
||||
help = "ONLY for pbkdf2: Number of rounds to calculate",
|
||||
default_value_t = 100
|
||||
)]
|
||||
rounds: u32,
|
||||
}
|
||||
|
||||
pub fn cmd_pwhash(args: PwhashArgs) -> anyhow::Result<()> {
|
||||
println!("Enter your password:");
|
||||
let password = rpassword::read_password()?;
|
||||
let salt = SaltString::generate(OsRng);
|
||||
let password_hash = match args.algorithm {
|
||||
PwhashAlgorithm::Argon2 => argon2::Argon2::default()
|
||||
.hash_password(password.as_bytes(), &salt)
|
||||
.unwrap(),
|
||||
PwhashAlgorithm::Pbkdf2 => pbkdf2::Pbkdf2
|
||||
.hash_password_customized(
|
||||
password.as_bytes(),
|
||||
None,
|
||||
None,
|
||||
Params {
|
||||
rounds: args.rounds,
|
||||
..Default::default()
|
||||
},
|
||||
&salt,
|
||||
)
|
||||
.unwrap(),
|
||||
};
|
||||
println!("{password_hash}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user