C# Sharp Exercises: Check username and password
C# Sharp String: Exercise-16 with Solution
Write a program in C# Sharp to check the username and password.
Sample Solution:-
C# Sharp Code:
using System;
public class Exercise16
{
public static void Main()
{
string username, password;
int ctr = 0;
Console.Write("\n\nCheck username and password :\n");
Console.Write("N.B. : Default user name and password is :abcd and 1234\n");
Console.Write("------------------------------------------------------\n");
do
{
Console.Write("Input a username: ");
username = Console.ReadLine();
Console.Write("Input a password: ");
password = Console.ReadLine();
if(username != "abcd" || password != "1234")
ctr++;
else
ctr=1;
}
while((username != "abcd" || password != "1234") && (ctr != 3));
if (ctr == 3)
Console.Write("\nLogin attemp three or more times. Try later!\n\n");
else
Console.Write("\nThe password entered successfully!\n\n");
}
}
Sample Output:
Check username and password : N.B. : Default username and password is : abcd and 1234 ------------------------------------------------------- Input a username: abcd Input a password: 1234 The password entered successfully!
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C# Sharp to read a sentence and replace lowercase characters by uppercase and vice-versa.
Next: Write a program in C# Sharp to search the position of a substring within a string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework