C# Program to Illustrate how User Authentication is Done

This is a C# Program to illustrate how user authentication is done.

Problem Description

This C# Program Illustrates how User Authentication is Done.

Problem Solution

Here the program accepts the username and password. It checks whether the password is correct with respect to the username.

Program/Source Code

Here is source code of the C# Program to Illustrate how User Authentication is Done. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Illustrate how User Authentication is Done
 */
using System;
class program
{
    public static void Main()
    {
        char[] password = new char[10];
        char[] username = new char[10];
        char ch;
        int i;
 
        Console.WriteLine("Enter User name < 3 characters > : ");
        for (int x = 0; x < 8; x++)
        {
            username[x] = Convert.ToChar(Console.Read());
        }
        Console.WriteLine("Enter the password < any 8 characters>: ");
        for (i = 0; i < 8; i++)
        {
            ch = Convert.ToChar(Console.Read());
            password[i] = ch;
            ch = '*';
            Console.WriteLine("{0}", ch);
        }
        password[i] = '\0';
        Console.WriteLine("\n Your Password is :");
        for (i = 0; i < 8; i++)
        {
            Console.Write("{0}", password[i]);
        }
        Console.ReadLine();
        Console.ReadLine();
    }
}
Program Explanation

This C# program is used to accept the username and password. Using for loop convert the password as ‘*’ character. Check whether the password is correct with respect to the username.

advertisement
advertisement
Runtime Test Cases
 
Enter User name < 3 characters > :
s
r
i
Enter the password < any 8 characters>:
*
s
*
*
*
r
*
*
*
i
*
 Your Password is :
s
r
i

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.