Remove unnecessary pwhash command

This commit is contained in:
Lennart
2025-07-02 23:43:18 +02:00
parent 26306fd661
commit a5663bf006
2 changed files with 3 additions and 55 deletions

View File

@@ -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(())
}

View File

@@ -4,8 +4,8 @@ use app::make_app;
use axum::ServiceExt;
use axum::extract::Request;
use clap::{Parser, Subcommand};
use commands::cmd_gen_config;
use commands::principals::{PrincipalsArgs, cmd_principals};
use commands::{cmd_gen_config, cmd_pwhash};
use config::{DataStoreConfig, SqliteDataStoreConfig};
use figment::Figment;
use figment::providers::{Env, Format, Toml};
@@ -43,7 +43,6 @@ struct Args {
#[derive(Debug, Subcommand)]
enum Command {
GenConfig(commands::GenConfigArgs),
Pwhash(commands::PwhashArgs),
Principals(PrincipalsArgs),
}
@@ -84,7 +83,6 @@ async fn main() -> Result<()> {
match args.command {
Some(Command::GenConfig(gen_config_args)) => cmd_gen_config(gen_config_args)?,
Some(Command::Pwhash(pwhash_args)) => cmd_pwhash(pwhash_args)?,
Some(Command::Principals(principals_args)) => cmd_principals(principals_args).await?,
None => {
let config: Config = Figment::new()