add passwords too!! not just gjp2

This commit is contained in:
Reid 2023-09-03 16:12:41 -07:00
parent ccafbfe860
commit e237cd9b8d
Signed by: reidlab
GPG key ID: 6C9EAA3364F962C8
6 changed files with 17 additions and 14 deletions

View file

@ -34,18 +34,18 @@ pub fn login_account(input: Form<FromLoginAccount>) -> status::Custom<&'static s
{
use crate::schema::accounts::dsl::*;
let account_id_gjp2_result = accounts
.select((id, gjp2))
let account_id_password_result = accounts
.select((id, password))
.filter(username.eq(input.userName.clone()))
.get_result::<(i32, String)>(connection);
match account_id_gjp2_result {
Ok(account_id_gjp2) => {
let user_id = helpers::accounts::get_user_id_from_account_id(account_id_gjp2.0);
match account_id_password_result {
Ok(account_id_password) => {
let user_id = helpers::accounts::get_user_id_from_account_id(account_id_password.0);
match verify_password(helpers::encryption::get_gjp2(input.password.clone()).as_bytes(), account_id_gjp2.1.as_str()) {
match verify_password(input.password.clone().as_bytes(), account_id_password.1.as_str()) {
Ok(_) => return status::Custom(Status::Ok,
Box::leak(format!("{},{}", account_id_gjp2.0, user_id).into_boxed_str())
Box::leak(format!("{},{}", account_id_password.0, user_id).into_boxed_str())
),
Err(_) => return status::Custom(Status::Ok, "-11")
};

View file

@ -5,6 +5,8 @@ use rocket::response::status;
use diesel::prelude::*;
use diesel::result::Error;
use password_auth::generate_hash;
use crate::CONFIG;
use crate::helpers;
use crate::db;
@ -60,7 +62,8 @@ pub fn register_account(input: Form<FormRegisterAccount>) -> status::Custom<&'st
let new_account = NewAccount {
username: input.userName.clone(),
gjp2: helpers::encryption::get_gjp2_hashed(input.password.clone()),
password: generate_hash(input.password.clone()),
gjp2: generate_hash(helpers::encryption::get_gjp2(input.password.clone())),
email: input.email.clone()
};
inserted_account = diesel::insert_into(accounts)