Menu
Coddy logo textTech

Recap - Validation Function

Part of the Fundamentals section of Coddy's Rust journey — lesson 54 of 75.

challenge icon

Challenge

Easy

Write a function named is_valid that gets two strings arguments, username and password.

The method will return True if the username and password are valid in the system, otherwise False.

Our system contains only two valid usernames - "admin" and "user".

The valid password for username "user" is "qweasd".

For username "admin" any password is valid!

Try it yourself

use std::io;

fn is_valid(username: String, password: String) -> bool {
    // Write your code below
}

fn main() {
    let mut input_user = String::new();
    let mut input_pass = String::new();
    io::stdin().read_line(&mut input_user).unwrap();
    io::stdin().read_line(&mut input_pass).unwrap();

    let user: String = input_user.trim().parse().unwrap();
    let pass: String = input_pass.trim().parse().unwrap();
    let res = is_valid(user, pass);
    println!("{}", res);
}

All lessons in Fundamentals