Skip to content

Commit

Permalink
Hash user's password to handle special chars
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed May 31, 2024
1 parent 344df1c commit a10bc6a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::db_models::{
Fedimint, LightningPayment, LightningReceive, NewFedimint, NewProfile, OnChainPayment,
OnChainReceive, Profile,
};
use bitcoin::hashes::hex::ToHex;
use bitcoin::hashes::{sha256, Hash};
use bitcoin::{Address, Txid};
use diesel::{
connection::SimpleConnection,
Expand Down Expand Up @@ -377,8 +379,8 @@ impl diesel::r2d2::CustomizeConnection<SqliteConnection, diesel::r2d2::Error>
{
fn on_acquire(&self, conn: &mut SqliteConnection) -> Result<(), diesel::r2d2::Error> {
(|| {
// FIXME: Special characters might fuck up
conn.batch_execute(&format!("PRAGMA key={}", self.key))?;
let hashed_password = sha256::Hash::hash(self.key.as_bytes());
conn.batch_execute(&format!("PRAGMA key={}", hashed_password.to_hex()))?;
if self.enable_wal {
conn.batch_execute("PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL;")?;
}
Expand Down

0 comments on commit a10bc6a

Please sign in to comment.