Spaces:
Runtime error
Runtime error
Download src/models.rs from arami21/auth-login: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/arami21/auth-login/resolve/main/src/models.rs
- Command line
-
hf download hf://spaces/arami21/auth-login/src/models.rs
-
curl -L -o models.rs https://huggingface.co/spaces/arami21/auth-login/resolve/main/src/models.rs
1.02 kB
| use argon2::{ | |
| Argon2, PasswordHasher, | |
| password_hash::{SaltString, rand_core::OsRng}, | |
| }; | |
| use serde::Deserialize; | |
| use sqlx::prelude::FromRow; | |
| pub struct UserRequest { | |
| username: String, | |
| password: String, | |
| } | |
| pub struct UserSql { | |
| id: i32, | |
| username: String, | |
| password: String, | |
| } | |
| trait Checked { | |
| fn username(&self) -> &String; | |
| fn password(&self) -> &String; | |
| fn is_null(&self) -> bool { | |
| self.username().trim() == "" || self.password().trim() == "" | |
| } | |
| fn hash_password(&self) -> String { | |
| let salt = SaltString::generate(&mut OsRng); | |
| let argon2 = Argon2::default(); | |
| let hashed_password = argon2 | |
| .hash_password(self.password().as_bytes(), &salt) | |
| .unwrap() | |
| .to_string(); | |
| hashed_password | |
| } | |
| } | |
| impl Checked for UserSql { | |
| fn username(&self) -> &String { | |
| &self.username | |
| } | |
| fn password(&self) -> &String { | |
| &self.password | |
| } | |
| } | |