|
|
|
@@ -4,7 +4,7 @@ use const_format::formatcp;
|
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
use tracing::{debug, error, warn};
|
|
|
|
|
use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors};
|
|
|
|
|
use zxcvbn::zxcvbn;
|
|
|
|
|
use zxcvbn::{zxcvbn, Score};
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
domain::model::session::Session,
|
|
|
|
@@ -348,14 +348,14 @@ fn validate_id(id: &Option<String>, process: &Process) -> Result<(), ValidationE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct PasswordValidationResult {
|
|
|
|
|
score: u8,
|
|
|
|
|
score: Score,
|
|
|
|
|
rating: f64, // 0 <= rating <= 1
|
|
|
|
|
suggestions: Vec<String>,
|
|
|
|
|
}
|
|
|
|
|
impl PasswordValidationResult {
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
PasswordValidationResult {
|
|
|
|
|
score: 0,
|
|
|
|
|
score: Score::Zero,
|
|
|
|
|
rating: 0.0,
|
|
|
|
|
suggestions: Vec::<String>::new(),
|
|
|
|
|
}
|
|
|
|
@@ -366,9 +366,7 @@ fn compute_password_score(
|
|
|
|
|
password: &str,
|
|
|
|
|
with_suggestions: Option<bool>,
|
|
|
|
|
) -> Option<PasswordValidationResult> {
|
|
|
|
|
let Ok(estimate) = zxcvbn(password, &[]) else {
|
|
|
|
|
return None;
|
|
|
|
|
};
|
|
|
|
|
let estimate = zxcvbn(password, &[]);
|
|
|
|
|
|
|
|
|
|
let mut result = PasswordValidationResult::new();
|
|
|
|
|
result.score = estimate.score();
|
|
|
|
@@ -396,7 +394,7 @@ fn validate_password(password: &Option<String>, process: &Process) -> Result<(),
|
|
|
|
|
if let Some(password) = password {
|
|
|
|
|
if let Some(result) = compute_password_score(password, Some(true)) {
|
|
|
|
|
// TODO: To configuration?
|
|
|
|
|
if result.score <= 2 {
|
|
|
|
|
if [Score::Zero, Score::One, Score::Two].contains(&result.score) {
|
|
|
|
|
let mut err = ValidationError::new(TOO_WEAK_PASSWORD_ERROR_NAME);
|
|
|
|
|
err.add_param(Cow::from("score"), &result.score);
|
|
|
|
|
err.add_param(Cow::from("rating"), &result.rating);
|
|
|
|
|