Compare commits
4 Commits
3ab68ecbe5
...
8dfc4f2694
Author | SHA1 | Date | |
---|---|---|---|
8dfc4f2694 | |||
b2da9b5dc5 | |||
ff578ab849
|
|||
0cffafcd77 |
@@ -27,11 +27,11 @@ tokio-stream = "0.1.15"
|
|||||||
base64 = "0.22.0"
|
base64 = "0.22.0"
|
||||||
const_format = "0.2.32"
|
const_format = "0.2.32"
|
||||||
rand = "0.9.1"
|
rand = "0.9.1"
|
||||||
validator = { version = "0.17.0", features = ["derive"] }
|
validator = { version = "0.20.0", features = ["derive"] }
|
||||||
# Http client
|
# Http client
|
||||||
reqwest = "0.12.0"
|
reqwest = "0.12.0"
|
||||||
# Password strength estimation
|
# Password strength estimation
|
||||||
zxcvbn = "2.2.2"
|
zxcvbn = { version = "3.0.0", features = ["ser"] }
|
||||||
# Image processing/conversion
|
# Image processing/conversion
|
||||||
image = "0.25.1"
|
image = "0.25.1"
|
||||||
# Get the application version
|
# Get the application version
|
||||||
|
@@ -4,7 +4,7 @@ use const_format::formatcp;
|
|||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use tracing::{debug, error, warn};
|
use tracing::{debug, error, warn};
|
||||||
use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors};
|
use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors};
|
||||||
use zxcvbn::zxcvbn;
|
use zxcvbn::{zxcvbn, Score};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
domain::model::session::Session,
|
domain::model::session::Session,
|
||||||
@@ -348,14 +348,14 @@ fn validate_id(id: &Option<String>, process: &Process) -> Result<(), ValidationE
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct PasswordValidationResult {
|
struct PasswordValidationResult {
|
||||||
score: u8,
|
score: Score,
|
||||||
rating: f64, // 0 <= rating <= 1
|
rating: f64, // 0 <= rating <= 1
|
||||||
suggestions: Vec<String>,
|
suggestions: Vec<String>,
|
||||||
}
|
}
|
||||||
impl PasswordValidationResult {
|
impl PasswordValidationResult {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
PasswordValidationResult {
|
PasswordValidationResult {
|
||||||
score: 0,
|
score: Score::Zero,
|
||||||
rating: 0.0,
|
rating: 0.0,
|
||||||
suggestions: Vec::<String>::new(),
|
suggestions: Vec::<String>::new(),
|
||||||
}
|
}
|
||||||
@@ -366,9 +366,7 @@ fn compute_password_score(
|
|||||||
password: &str,
|
password: &str,
|
||||||
with_suggestions: Option<bool>,
|
with_suggestions: Option<bool>,
|
||||||
) -> Option<PasswordValidationResult> {
|
) -> Option<PasswordValidationResult> {
|
||||||
let Ok(estimate) = zxcvbn(password, &[]) else {
|
let estimate = zxcvbn(password, &[]);
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut result = PasswordValidationResult::new();
|
let mut result = PasswordValidationResult::new();
|
||||||
result.score = estimate.score();
|
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(password) = password {
|
||||||
if let Some(result) = compute_password_score(password, Some(true)) {
|
if let Some(result) = compute_password_score(password, Some(true)) {
|
||||||
// TODO: To configuration?
|
// 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);
|
let mut err = ValidationError::new(TOO_WEAK_PASSWORD_ERROR_NAME);
|
||||||
err.add_param(Cow::from("score"), &result.score);
|
err.add_param(Cow::from("score"), &result.score);
|
||||||
err.add_param(Cow::from("rating"), &result.rating);
|
err.add_param(Cow::from("rating"), &result.rating);
|
||||||
|
Reference in New Issue
Block a user