vtse/vtse-server/src/user.rs

29 lines
677 B
Rust

use sodiumoxide::crypto::pwhash::{
argon2id13::HashedPassword,
argon2id13::{pwhash, MEMLIMIT_INTERACTIVE, OPSLIMIT_INTERACTIVE},
};
use std::convert::TryFrom;
use vtse_common::user::Password;
#[derive(sqlx::Type)]
#[sqlx(transparent)]
pub(crate) struct SaltedPassword(HashedPassword);
impl TryFrom<Password> for SaltedPassword {
type Error = ();
fn try_from(password: Password) -> Result<Self, Self::Error> {
Ok(Self(pwhash(
password.as_bytes(),
OPSLIMIT_INTERACTIVE,
MEMLIMIT_INTERACTIVE,
)?))
}
}
impl AsRef<[u8]> for SaltedPassword {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}