Password as string Learn programming C#

Lesson:

Basic Data Types


Exercise:

Password as string


Objetive:

Write a C# program to ask the user for their username and password (both should be strings) and repeat it as many times as necessary until the entered name is "username" and the password is "password".


Code:

using System;
public class exercise51
{
    public static void Main()
    {
        string user, password;

        do
        {
            Console.Write("Enter a user: ");
            user = Console.ReadLine();

            Console.Write("Enter a password: ");
            password = Console.ReadLine();
        }
        while (user != "user" && password != "password");
        Console.WriteLine("Bye!");
    }
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.