rudabai 2.0.4

A robot motor management system and custom database
use std::io::{self, Read, ErrorKind};
use std::fs::File;
fn main(){
    //start system

    //enter username
    println!("enter username");
    let mut username = String::new();
    io::stdin().read_line(&mut username).expect("failed to read username");

    //enter password
    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");

/*    //match password and username to stored values
    //TODO: encrypt these
    let mut stored_password_file = File::open(username);
    let mut stored_password = String::new();
    stored_password_file.read_to_string(&mut stored_password)?;
    Ok(stored_password);
//    let mut storedPassword = fs::read_to_string("{username}.txt");
    if password.result == stored_password{
        println!("Welcome to your database");
    }*/
    check_password(username);
     println!("welcome");//{}", username.to_string())
}
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(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(); // : &str= "username";
    let registration_confirm;
    /*let mut user_file = match user_file{
        //Ok(file) => user_exists,
        //Err(e) => createUser()
        password => println!("{}", user_exists), //get if file exists or...
        _ => {
            let mut passFile = File::create(username);
            passFile.write_all(password);
        }
    }; */
    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);
  //  println!("{}", registration_confirm);
    return registration_confirm;
}