use std::error::Error;
use log::{debug, error};
use pam_client::{conv_cli::Conversation, Context, Flag};
pub(crate) fn password_input(
password: bool,
context: &mut Context<Conversation>,
) -> Result<(), Box<dyn Error>> {
if password {
debug!("Password will be asked a maximum of 3 time to the user");
let mut count: u8 = 0;
while count < 3 {
if let Ok(()) = context.authenticate(Flag::DISALLOW_NULL_AUTHTOK) {
break;
}
error!("Password was incorrect! Will be report to administrator!");
eprintln!("Password was incorrect! Will be report to administrator!");
count = count.saturating_add(1);
}
if count == 3 {
return Err(From::from("You have made three mistake! Rudo Out!"));
}
}
Ok(())
}