password changes, account name restrictions
This commit is contained in:
+10
-7
@@ -22,6 +22,7 @@ use failure::Error;
|
||||
use failure::{err_msg, format_err};
|
||||
|
||||
static PASSWORD_MIN_LEN: usize = 3;
|
||||
static PASSWORD_ROUNDS: u32 = 10;
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct Account {
|
||||
@@ -70,11 +71,11 @@ pub fn chat_wheel(_db: &Db, _id: Uuid) -> Result<Vec<String>, Error> {
|
||||
return Ok(vec![
|
||||
"gg".to_string(),
|
||||
"glhf".to_string(),
|
||||
"hmm".to_string(),
|
||||
"ok".to_string(),
|
||||
"ez".to_string(),
|
||||
"rekt".to_string(),
|
||||
"thx".to_string(),
|
||||
"nice".to_string(),
|
||||
"wp".to_string(),
|
||||
"ok".to_string(),
|
||||
"...".to_string(),
|
||||
])
|
||||
}
|
||||
@@ -226,8 +227,7 @@ pub fn set_password(tx: &mut Transaction, id: Uuid, current: &String, password:
|
||||
return Err(MnmlHttpError::BadRequest);
|
||||
}
|
||||
|
||||
let rounds = 8;
|
||||
let password = hash(&password, rounds)?;
|
||||
let password = hash(&password, PASSWORD_ROUNDS)?;
|
||||
|
||||
let query = "
|
||||
UPDATE accounts
|
||||
@@ -327,10 +327,13 @@ pub fn create(name: &String, password: &String, tx: &mut Transaction) -> Result<
|
||||
return Err(MnmlHttpError::AccountNameNotProvided);
|
||||
}
|
||||
|
||||
if name.len() > 20 {
|
||||
return Err(MnmlHttpError::AccountNameUnacceptable);
|
||||
}
|
||||
|
||||
let id = Uuid::new_v4();
|
||||
let img = Uuid::new_v4();
|
||||
let rounds = 12;
|
||||
let password = hash(&password, rounds)?;
|
||||
let password = hash(&password, PASSWORD_ROUNDS)?;
|
||||
|
||||
let mut rng = thread_rng();
|
||||
let token: String = iter::repeat(())
|
||||
|
||||
+4
-1
@@ -44,7 +44,9 @@ pub enum MnmlHttpError {
|
||||
AccountNameNotProvided,
|
||||
#[fail(display="account name unavailable")]
|
||||
AccountNameUnavailable,
|
||||
#[fail(display="account not found")]
|
||||
#[fail(display="account name unavailable")]
|
||||
AccountNameUnacceptable,
|
||||
#[fail(display="account name is unacceptable. 20 char max")]
|
||||
AccountNotFound,
|
||||
#[fail(display="password does not match")]
|
||||
PasswordNotMatch,
|
||||
@@ -122,6 +124,7 @@ impl From<MnmlHttpError> for IronError {
|
||||
|
||||
MnmlHttpError::AccountNameNotProvided |
|
||||
MnmlHttpError::AccountNameUnavailable |
|
||||
MnmlHttpError::AccountNameUnacceptable |
|
||||
MnmlHttpError::AccountNotFound |
|
||||
MnmlHttpError::BadRequest |
|
||||
MnmlHttpError::PasswordUnacceptable => (m_err.compat(), status::BadRequest),
|
||||
|
||||
Reference in New Issue
Block a user