I am trying to compare two strings in Rust for a project I am doing in my free time in order to become more familiar with Rust, however I have run in to a small issue. Whenever I try to do string1 == string2
all I get is false
. Here is the code that I am using:
use std::io;
fn main() {
let mut username = String::new();
let mut password = String::new();
let username = "Miku";
let password = "password";
loop{
let mut userAttempt = String::new();
let mut passAttempt = String::new();
println!("Enter username:\n> ");
io::stdin().read_line(&mut userAttempt).expect("Failed to read line");
println!("Enter password:\n> ");
io::stdin().read_line(&mut passAttempt).expect("Failed to read line");
println!("{}", userAttempt == username);
if userAttempt == username{
println!("Got here!");
if passAttempt == password{
println!("Logged in successfully.");
}
}
}
}