pub fn bcrypt_format<T: ?Sized + AsRef<[u8]>, K: ?Sized + AsRef<[u8]>>(
    cost: u8,
    salt: &K,
    password: &T,
) -> Result<String, &'static str> {
    if cost >= 32 {
        return Err("Cost needs to be smaller than 32.");
    }

    let password = password.as_ref();

    let password_len = password.len();

    if password_len == 0 {
        return Err("The password is empty.");
    }

    if password_len > 72 {
        return Err("The length of the password should not be bigger than 72.");
    }

    let salt = salt.as_ref();

    let mut hash = [0u8; 24];

    let salt = if salt.len() != 16 {
        let new_salt = *md5::compute(salt);
        bcrypt::bcrypt(cost as u32, &new_salt, password, &mut hash);

        base64::encode_config(&new_salt, base64::BCRYPT)
    } else {
        bcrypt::bcrypt(cost as u32, salt, password, &mut hash);

        base64::encode_config(salt, base64::BCRYPT)
    };

    let hash = base64::encode_config(&hash[..23], base64::BCRYPT);

    Ok(format!("$2b${:02}${}{}", cost, salt, hash))
}
/// Use bcrypt to hash a password (the null-terminated byte will not be added automatically) whose length is not bigger than 72 bytes to 24 bytes data. The result will be in Modular Crypt Format. If the salt is not 16 bytes, it will be MD5 hashed first.
Use bcrypt to hash a password (the null-terminated byte will not be added automatically) whose length is not bigger than 72 bytes to 24 bytes data. The result will be in Modular Crypt Format. If the salt is not 16 bytes, it will be MD5 hashed first.
Use bcrypt to hash a password ( the null - terminated byte will not be added automatically ) whose length is not bigger than 72 bytes to 24 bytes data . The result will be in Modular Crypt Format . If the salt is not 16 bytes it will be MD5 hashed first .
pub fn bcrypt_format<T: ?Sized + AsRef<[u8]>, K: ?Sized + AsRef<[u8]>>(
    cost: u8,
    salt: &K,
    password: &T,
) -> Result<String, &'static str> {
    if cost >= 32 {
        return Err("Cost needs to be smaller than 32.");
    }
    let password = password.as_ref();
    let password_len = password.len();
    if password_len == 0 {
        return Err("The password is empty.");
    }
    if password_len > 72 {
        return Err("The length of the password should not be bigger than 72.");
    }
    let salt = salt.as_ref();
    let mut hash = [0u8; 24];
    let salt = if salt.len() != 16 {
        let new_salt = *md5::compute(salt);
        bcrypt::bcrypt(cost as u32, &new_salt, password, &mut hash);
        base64::encode_config(&new_salt, base64::BCRYPT)
    } else {
        bcrypt::bcrypt(cost as u32, salt, password, &mut hash);
        base64::encode_config(salt, base64::BCRYPT)
    };
    let hash = base64::encode_config(&hash[..23], base64::BCRYPT);
    Ok(format!("$2b${:02}${}{}", cost, salt, hash))
}
pub fn bcrypt_format < T : ? Sized + AsRef < [ u8 ] > , K : ? Sized + AsRef < [ u8 ] > > ( cost : u8 , salt : & K , password : & T , ) -> Result < String , & ' static str > { if cost >= 32 { return Err ( " " ) ; } let password = password . as_ref ( ) ; let password_len = password . len ( ) ; if password_len == 0 { return Err ( " " ) ; } if password_len > 72 { return Err ( " " ) ; } let salt = salt . as_ref ( ) ; let mut hash = [ 0u8 ; 24 ] ; let salt = if salt . len ( ) != 16 { let new_salt = * md5 :: compute ( salt ) ; bcrypt :: bcrypt ( cost as u32 , & new_salt , password , & mut hash ) ; base64 :: encode_config ( & new_salt , base64 :: BCRYPT ) } else { bcrypt :: bcrypt ( cost as u32 , salt , password , & mut hash ) ; base64 :: encode_config ( salt , base64 :: BCRYPT ) } ; let hash = base64 :: encode_config ( & hash [ .. 23 ] , base64 :: BCRYPT ) ; Ok ( format ! ( " " cost salt hash ) ) }
Use bcrypt to hash a password (the null-terminated byte will not be added automatically) whose length is not bigger than 72 bytes to 24 bytes data.
Use bcrypt to hash a password ( the null - terminated byte will not be added automatically ) whose length is not bigger than 72 bytes to 24 bytes data .
cost
u8
salt
&K
password
&T