Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# user and password verification

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));
        }
 
PREVIOUS NEXT
Tagged: #user #password #verification
ADD COMMENT
Topic
Name
4+7 =