Skip to content

Commit

Permalink
remove salt from table
Browse files Browse the repository at this point in the history
  • Loading branch information
jb-alvarado committed Dec 11, 2023
1 parent 136875e commit 15f4114
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 12 deletions.
3 changes: 1 addition & 2 deletions ffplayout-api/src/api/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ pub async fn login(pool: web::Data<Pool<Sqlite>>, credentials: web::Json<User>)
let pass = user.password.clone();
let hash = PasswordHash::new(&pass).unwrap();
user.password = "".into();
user.salt = None;

if Argon2::default()
.verify_password(credentials.password.as_bytes(), &hash)
Expand Down Expand Up @@ -307,7 +306,7 @@ async fn update_user(
.hash_password(data.password.clone().as_bytes(), &salt)
.unwrap();

fields.push_str(format!("password = '{password_hash}', salt = '{salt}'").as_str());
fields.push_str(format!("password = '{password_hash}'").as_str());
}

if handles::update_user(&pool.into_inner(), *id, fields)
Expand Down
7 changes: 2 additions & 5 deletions ffplayout-api/src/db/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ async fn create_schema(conn: &Pool<Sqlite>) -> Result<SqliteQueryResult, sqlx::E
mail TEXT NOT NULL,
username TEXT NOT NULL,
password TEXT NOT NULL,
salt TEXT NOT NULL,
role_id INTEGER NOT NULL DEFAULT 2,
channel_id INTEGER NOT NULL DEFAULT 1,
FOREIGN KEY (role_id) REFERENCES roles (id) ON UPDATE SET NULL ON DELETE SET NULL,
Expand Down Expand Up @@ -217,7 +216,7 @@ pub async fn select_role(conn: &Pool<Sqlite>, id: &i32) -> Result<Role, sqlx::Er
}

pub async fn select_login(conn: &Pool<Sqlite>, user: &str) -> Result<User, sqlx::Error> {
let query = "SELECT id, mail, username, password, salt, role_id FROM user WHERE username = $1";
let query = "SELECT id, mail, username, password, role_id FROM user WHERE username = $1";

sqlx::query_as(query).bind(user).fetch_one(conn).await
}
Expand Down Expand Up @@ -249,14 +248,12 @@ pub async fn insert_user(
.hash_password(user.password.clone().as_bytes(), &salt)
.unwrap();

let query =
"INSERT INTO user (mail, username, password, salt, role_id) VALUES($1, $2, $3, $4, $5)";
let query = "INSERT INTO user (mail, username, password, role_id) VALUES($1, $2, $3, $4)";

sqlx::query(query)
.bind(user.mail)
.bind(user.username)
.bind(password_hash.to_string())
.bind(salt.to_string())
.bind(user.role_id)
.execute(conn)
.await
Expand Down
3 changes: 0 additions & 3 deletions ffplayout-api/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ pub struct User {
pub password: String,
#[sqlx(default)]
#[serde(skip_serializing)]
pub salt: Option<String>,
#[sqlx(default)]
#[serde(skip_serializing)]
pub role_id: Option<i32>,
#[sqlx(default)]
#[serde(skip_serializing)]
Expand Down
1 change: 0 additions & 1 deletion ffplayout-api/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ pub async fn run_args() -> Result<(), i32> {
mail: Some(args.mail.unwrap()),
username: username.clone(),
password: args.password.unwrap(),
salt: None,
role_id: Some(1),
channel_id: Some(1),
token: None,
Expand Down

0 comments on commit 15f4114

Please sign in to comment.