lexa_framework/security/password.rs
1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ Copyright: (c) 2023, Mike 'PhiSyX' S. (https://github.com/PhiSyX) ┃
3// ┃ SPDX-License-Identifier: MPL-2.0 ┃
4// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
5// ┃ ┃
6// ┃ This Source Code Form is subject to the terms of the Mozilla Public ┃
7// ┃ License, v. 2.0. If a copy of the MPL was not distributed with this ┃
8// ┃ file, You can obtain one at https://mozilla.org/MPL/2.0/. ┃
9// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
10
11#[cfg(feature = "encryption-argon2")]
12pub mod argon2;
13
14// --------- //
15// Interface //
16// --------- //
17
18pub trait PasswordEncryption: Clone {
19 fn new(secret: impl ToString) -> Self;
20
21 /// Chiffre un mot de passe avec un algorithme de hachage / chiffrement.
22 fn encrypt_password(
23 &self,
24 credential: impl AsRef<str>,
25 ) -> Result<String, Box<dyn std::error::Error + Send + Sync>>;
26
27 /// Vérifie le mot de passe à l'aide du hachage codé.
28 fn verify_password(
29 &self,
30 encrypted: impl AsRef<str>,
31 credential: impl AsRef<str>,
32 ) -> bool;
33}