This repository has been archived on 2026-04-25. You can view files and clone it, but cannot push or open issues or pull requests.
RustyPass/src/interface.rs

101 lines
3.2 KiB
Rust
Raw Normal View History

// Libraries
2024-06-14 13:32:02 -05:00
use std::{io, process::exit};
// Functions
2024-06-14 13:32:02 -05:00
fn get_credentials() -> (String, String) {
// Variables
let mut username: String = String::new();
let mut password: String = String::new();
// Asking for the username
println!("Username: ");
io::stdin().read_line(&mut username).expect("Failed to read line");
username = String::from(username.to_lowercase().trim());
// Asking for the password
println!("Password: ");
io::stdin().read_line(&mut password).expect("Failed to read line");
password = String::from(password.trim());
return (username, password);
2024-06-14 13:32:02 -05:00
}
pub fn int_auth() -> (String, String) {
println!(" - LOGIN - ");
return get_credentials();
}
pub fn int_reg() -> (String, String) {
// Register form
println!(" - REGISTER - ");
let (username, password) = get_credentials();
// Confirming password
let mut cpassword: String = String::new();
println!("Confirm Password: ");
io::stdin().read_line(&mut cpassword).expect("Failed to read line");
cpassword = String::from(cpassword.trim());
// Valid password?
if password != cpassword {
println!("Passwords do not match!");
exit(0);
} else {
return (username, password);
}
2024-06-15 13:23:52 -05:00
}
pub fn int_welcome(username: &String) -> String {
// Variables
let mut user_input: String = String::new();
// Welcome message
println!("\n - RUSTYPASS - ");
println!("Welcome, {}!", username);
println!("Please select one of the following options: ");
println!("\n1) View a Password");
println!("2) Create a Password");
println!("3) Generate a Password");
println!("4) Quit");
io::stdin().read_line(&mut user_input).expect("Failed to read line");
// Returning what the user said
return String::from(user_input.trim());
}
pub fn int_gen() -> (u32, bool, bool) {
// Variables
let mut raw_pass_len: String = String::new();
let mut raw_pass_num: String = String::new();
let mut raw_pass_spe: String = String::new();
// Asking the user the big questions
println!(" - Password Generator - ");
println!("Before we give you a password, just a few questions!");
println!("How long should your password be?");
println!("Select size[number]: ");
io::stdin().read_line(&mut raw_pass_len).expect("Failed to read line.");
println!("Would you like numbers to be included in your password?");
println!("Select option[y/n]: ");
io::stdin().read_line(&mut raw_pass_num).expect("Failed to read line.");
println!("Would you like special characters to be included in your password?");
println!("Select option[y/n]: ");
io::stdin().read_line(&mut raw_pass_spe).expect("Failed to read line.");
// Converting the stuff
let pass_len: u32 = raw_pass_len.trim().parse().unwrap();
let str_pass_num: String = String::from(raw_pass_num.to_lowercase().trim());
let str_pass_spe: String = String::from(raw_pass_spe.to_lowercase().trim());
// Y/N to bool:
let pass_num: bool = if str_pass_num == "y" {
true
} else{
false
};
let pass_spe: bool = if str_pass_spe == "y" {
true
} else {
false
};
// Returning all of the values
return (pass_len, pass_num, pass_spe);
}