use std::io::{self, Read, ErrorKind};
use std::fs::File;
fn main(){
println!("enter username");
let mut username = String::new();
io::stdin().read_line(&mut username).expect("failed to read username");
println!("Hi {username} please enter password");
let mut password = String::new();
io::stdin().read_line(&mut password).expect("failed to read password");
println!("logging you in");
check_password(username);
println!("welcome");}
fn check_password(myUsername: String) -> Result<String, io::Error>{
let password_file = File::open(myUsername);
let mut password_file = match password_file{
Ok(file) => file,
Err(e) => return Err(e)
};
let mut password = String::new();
match password_file.read_to_string(&mut password){
Ok(_) => Ok("successful login".to_string()),
Err(e) => Err(e)
}
}
fn register_new_user(username: String, password: String) -> Result<usize, io::Error>{
let user_file = File::open("{username}.txt");
let mut user_exists = "username already in use";
let mut user_file_content : &mut String = &mut"".to_string(); let registration_confirm;
let mut user_file = match user_file{
Ok(file) => file,
Err(error) => match error.kind(){
ErrorKind::NotFound => match File::create("{username}.txt"){
Ok(fc) => fc,
Err(e) => panic!("Problem creating the file: {:?}", e)
},
other_error => {
panic!("Problem opening the file: {:?}", other_error);
}
}
};
registration_confirm = user_file.read_to_string(user_file_content);
return registration_confirm;
}