feat: use rust-crypto to encrypt password with sha3 hash alg
This commit is contained in:
parent
4309dd90bb
commit
461744c8a4
@ -17,4 +17,5 @@ serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
tera = "*"
|
||||
pulldown-cmark = { version = "0.1.2", default-features = false }
|
||||
chrono = { version = "*", features = ["serde"] }
|
||||
chrono = { version = "*", features = ["serde"] }
|
||||
rust-crypto = "^0.2"
|
@ -15,6 +15,8 @@ extern crate serde;
|
||||
extern crate serde_derive;
|
||||
extern crate tera;
|
||||
|
||||
extern crate crypto;
|
||||
|
||||
|
||||
use dotenv::dotenv;
|
||||
use rocket_contrib::Template;
|
||||
|
@ -3,10 +3,12 @@ use chrono::NaiveDate;
|
||||
use chrono::NaiveTime;
|
||||
use serde::Serialize;
|
||||
use chrono::NaiveDateTime;
|
||||
use crypto::sha3::Sha3;
|
||||
use crypto::digest::Digest;
|
||||
|
||||
#[derive(Queryable, Debug, Serialize)]
|
||||
#[belongs_to(User)]
|
||||
#[table_name= "posts"]
|
||||
#[table_name = "posts"]
|
||||
pub struct Post {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
@ -28,8 +30,16 @@ pub struct User {
|
||||
}
|
||||
|
||||
impl User {
|
||||
|
||||
pub fn authenticated(&self, password: &str) -> bool {
|
||||
true
|
||||
let mut hasher = Sha3::sha3_256();
|
||||
hasher.input_str(password);
|
||||
let result = hasher.result_str();
|
||||
|
||||
if self.password.eq(&result) {
|
||||
true
|
||||
}else {
|
||||
false
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use schema::{users, users::dsl::*};
|
||||
use rocket::http::Status;
|
||||
use pg_pool::DbConn;
|
||||
use rocket::http::Cookie;
|
||||
use crypto::sha3::Sha3;
|
||||
|
||||
|
||||
#[get("/login")]
|
||||
|
Loading…
Reference in New Issue
Block a user