tools: add read_and_verify_password helper
add a helper to perform some basic checks on password prompts. - verification (asks for a 2nd time) - check length also use the new helper where password input in tty is taken to reduce duplicate code. this helper should be used when creating keys, changing passphrases etc. note: this helper can be extended later on to provide better checks for password strength. Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
This commit is contained in:
committed by
Dietmar Maurer
parent
ea5061979b
commit
cbe01dc5c7
@ -86,3 +86,19 @@ pub fn read_password(query: &str) -> Result<Vec<u8>, Error> {
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_and_verify_password(prompt: &str) -> Result<Vec<u8>, Error> {
|
||||
|
||||
let password = String::from_utf8(crate::tools::tty::read_password(prompt)?)?;
|
||||
let verify_password = String::from_utf8(crate::tools::tty::read_password("Verify Password: ")?)?;
|
||||
|
||||
if password != verify_password {
|
||||
bail!("Passwords do not match!");
|
||||
}
|
||||
|
||||
if password.len() < 5 {
|
||||
bail!("Password too short!");
|
||||
}
|
||||
|
||||
Ok(password.into_bytes())
|
||||
}
|
||||
|
Reference in New Issue
Block a user