fmt: repo-wide baseline (WI-2, issue #2)
This commit is contained in:
parent
899fde8fc3
commit
337e9bcf2c
19 changed files with 847 additions and 335 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use argon2::{
|
||||
password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
|
||||
Argon2,
|
||||
password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
|
||||
};
|
||||
|
||||
pub fn hash_password(password: &str) -> Result<String, argon2::password_hash::Error> {
|
||||
|
|
@ -17,5 +17,7 @@ pub fn verify_password(password: &str, hash: &str) -> bool {
|
|||
Ok(h) => h,
|
||||
Err(_) => return false,
|
||||
};
|
||||
Argon2::default().verify_password(password.as_bytes(), &parsed).is_ok()
|
||||
Argon2::default()
|
||||
.verify_password(password.as_bytes(), &parsed)
|
||||
.is_ok()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use chrono::{Duration, Utc};
|
||||
use jsonwebtoken::{DecodingKey, EncodingKey, Header, Validation};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use chrono::{Utc, Duration};
|
||||
|
||||
fn jwt_secret() -> Vec<u8> {
|
||||
std::env::var("JWT_SECRET")
|
||||
|
|
@ -16,7 +16,11 @@ pub struct Claims {
|
|||
pub exp: usize,
|
||||
}
|
||||
|
||||
pub fn create_token(user_id: u32, name: &str, role: &str) -> Result<String, jsonwebtoken::errors::Error> {
|
||||
pub fn create_token(
|
||||
user_id: u32,
|
||||
name: &str,
|
||||
role: &str,
|
||||
) -> Result<String, jsonwebtoken::errors::Error> {
|
||||
let exp = Utc::now()
|
||||
.checked_add_signed(Duration::hours(24))
|
||||
.expect("valid timestamp")
|
||||
|
|
@ -39,9 +43,6 @@ pub fn create_token(user_id: u32, name: &str, role: &str) -> Result<String, json
|
|||
pub fn verify_token(token: &str) -> Result<Claims, jsonwebtoken::errors::Error> {
|
||||
let mut validation = Validation::default();
|
||||
validation.leeway = 60;
|
||||
jsonwebtoken::decode::<Claims>(
|
||||
token,
|
||||
&DecodingKey::from_secret(&jwt_secret()),
|
||||
&validation,
|
||||
).map(|d| d.claims)
|
||||
jsonwebtoken::decode::<Claims>(token, &DecodingKey::from_secret(&jwt_secret()), &validation)
|
||||
.map(|d| d.claims)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue