mirror of https://github.com/raftario/filite.git
Merge pull request #15 from steven-joruk/no-password-no-auth
No password no auth
This commit is contained in:
commit
4d835ed4c7
|
@ -31,6 +31,11 @@ fn auth(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if password_hash == setup::hash("").as_slice() {
|
||||||
|
identity.remember("guest".into());
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let header = match request.headers().get("Authorization") {
|
let header = match request.headers().get("Authorization") {
|
||||||
Some(h) => match h.to_str() {
|
Some(h) => match h.to_str() {
|
||||||
Ok(h) => h,
|
Ok(h) => h,
|
||||||
|
|
33
src/setup.rs
33
src/setup.rs
|
@ -251,14 +251,33 @@ pub fn init() -> Config {
|
||||||
if !password_path.exists() {
|
if !password_path.exists() {
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
let mut stdin = stdin.lock();
|
let mut stdin = stdin.lock();
|
||||||
println!("Enter the password to use:");
|
|
||||||
let mut password = String::new();
|
let mut password = String::new();
|
||||||
stdin.read_line(&mut password).unwrap_or_else(|e| {
|
|
||||||
eprintln!("Can't read password: {}", e);
|
loop {
|
||||||
process::exit(1);
|
println!("Enter the password to use: ");
|
||||||
});
|
stdin.read_line(&mut password).unwrap_or_else(|e| {
|
||||||
password = password.replace("\r", "");
|
eprintln!("Can't read password: {}", e);
|
||||||
password = password.replace("\n", "");
|
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);
|
let password_hash = hash(&password);
|
||||||
fs::write(&password_path, password_hash.as_slice()).unwrap_or_else(|e| {
|
fs::write(&password_path, password_hash.as_slice()).unwrap_or_else(|e| {
|
||||||
eprintln!("Can't write password: {}", e);
|
eprintln!("Can't write password: {}", e);
|
||||||
|
|
Loading…
Reference in New Issue