Merge pull request #15 from steven-joruk/no-password-no-auth

No password no auth
This commit is contained in:
Raphaël Thériault 2019-10-27 18:54:59 -04:00 committed by GitHub
commit 4d835ed4c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 7 deletions

View File

@ -31,6 +31,11 @@ fn auth(
return Ok(());
}
if password_hash == setup::hash("").as_slice() {
identity.remember("guest".into());
return Ok(());
}
let header = match request.headers().get("Authorization") {
Some(h) => match h.to_str() {
Ok(h) => h,

View File

@ -251,14 +251,33 @@ pub fn init() -> Config {
if !password_path.exists() {
let stdin = io::stdin();
let mut stdin = stdin.lock();
println!("Enter the password to use:");
let mut password = String::new();
stdin.read_line(&mut password).unwrap_or_else(|e| {
eprintln!("Can't read password: {}", e);
process::exit(1);
});
password = password.replace("\r", "");
password = password.replace("\n", "");
loop {
println!("Enter the password to use: ");
stdin.read_line(&mut password).unwrap_or_else(|e| {
eprintln!("Can't read password: {}", e);
process::exit(1);
});
password = password.replace("\r", "");
password = password.replace("\n", "");
if !password.is_empty() {
break;
}
println!("Are you sure you want to leave an empty password? This will disable authentication: [y/N]: ");
let mut answer = String::new();
stdin.read_line(&mut answer).unwrap_or_else(|e| {
eprintln!("Can't read answer: {}", e);
process::exit(1);
});
if answer.trim() == "y" {
break;
}
}
let password_hash = hash(&password);
fs::write(&password_path, password_hash.as_slice()).unwrap_or_else(|e| {
eprintln!("Can't write password: {}", e);