Skip to content

Commit

Permalink
feat(auth): salt doesn't need to be stored separately from hash
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcclung committed Apr 28, 2024
1 parent 2fafd19 commit 3df17cd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions migrations/0009_remove_salt_from_users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add migration script here
ALTER TABLE users DROP COLUMN salt;
2 changes: 1 addition & 1 deletion src/routes/newsletter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub async fn publish_newsletter(

let user = sqlx::query!(
r#"
SELECT id, password_hash, salt FROM users WHERE username = $1
SELECT id, password_hash FROM users WHERE username = $1
"#,
credentials.username,
)
Expand Down
9 changes: 4 additions & 5 deletions tests/api/test_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ impl TestApp {
.to_string();

sqlx::query!(
"INSERT INTO users (id, username, password_hash, salt)
VALUES ($1, $2, $3, $4)
ON CONFLICT (username) DO UPDATE SET password_hash = EXCLUDED.password_hash, salt = EXCLUDED.salt;",
"INSERT INTO users (id, username, password_hash)
VALUES ($1, $2, $3)
ON CONFLICT (username) DO UPDATE SET password_hash = EXCLUDED.password_hash",
Uuid::new_v4(),
username,
password_hash,
salt.to_string()
password_hash
)
.execute(&self.pool)
.await
Expand Down

0 comments on commit 3df17cd

Please sign in to comment.