Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# validate username and password

static List<KeyValuePair<string, string>> UsersAndPasswords = new List<KeyValuePair<string, string>>();
        static void Main(string[] args)
        {
            AddUser("Cat", "mecat");
            Console.Write("User Name: ");
            string? InputetedUserName = Console.ReadLine();
            Console.Write("
Password: ");
            string? InputetedPass = Console.ReadLine();
            bool foundUser = false;
            bool isAccessVerified = false;
            for (int i = 0; i < UsersAndPasswords.Count; i++)
            {
                if (UsersAndPasswords[i].Key == InputetedUserName)
                {
                    foundUser = true;
                    if (UsersAndPasswords[i].Value == InputetedPass)
                    {
                        Console.WriteLine("Access Verified.");
                        isAccessVerified = true;
                    }
                    else
                    {
                        Console.WriteLine("Password is incorrect.");
                    }
                    break;
                }
            }
            if (!foundUser)
                Console.WriteLine("User not found.");
            if (isAccessVerified)
            {
                //continue code...
            }
        }

        private static void AddUser(string username, string password)
        {
            UsersAndPasswords.Add(new KeyValuePair<string, string>(username,password));
        }
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to authorize token when consuming api in c# 
Csharp :: Permutation and Combination in C# 
Csharp :: how to play a random sound at the position that you want in unity 
Csharp :: windows 10 see how long a program has been running 
Csharp :: c# bitwise or 
Csharp :: belgium 251 PRG Prac 
Csharp :: how to use javascriptexecutor for loop in selenium c# 
Csharp :: asp.net core mvc not triggering client side validation 
Csharp :: c# operators 
Csharp :: get image information using c# 
Csharp :: c# reflection 
Csharp :: page refresh on button click in c# 
Csharp :: shallow copy vs deep copy c# 
Csharp :: app rating within game in unity 
Csharp :: change object material unity 
Csharp :: what is c# used for 
Csharp :: C# IEnumerable access element at index 
Csharp :: c# array inst working 
Csharp :: How to use multiple Commands for one ViewModel 
Csharp :: convert foreach to linq c# 
Html :: html input integer and positive 
Html :: html anchor tag open in new tab 
Html :: fontawesome phone icon 
Html :: bootstrap 5 overflow 
Html :: space character in react html 
Html :: ascii corners 
Html :: bootstrap 5 font weight 
Html :: NavBar Bootstrap v4 Fix 
Html :: & in html 
Html :: commenting in html 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =