C# Login screen "Multiple users"

Now C# isn't my thing and this wont work without you changing it but...

Code:
onclick event of the login button ()

int i =0;
int password;
string username;
password = int.Parse(mtbPassword.Text);
username = Convert.ToString(cbxUsername.Text);

count ++;
if count > 3 exit sub;

for each string item in usernames {
  if item.equals(username) {
    if passwords[i].equals(password) {
       'login or whatever
       count = 0;
    } else {
       'incorrect password you have "count" goes left
       exit sub;
    }
  }
  i++;
}
 
Last edited:
Any reason why the password must be an int?
If the user entered text as the password, you'll probably get an error message.

username = Convert.ToString(cbxUsername.Text);
username = cbxUsername.text is fine.
 
Raining outside. Try this.
Code:
//global
            string[][] userList = new[] { new[] { "Christopher Lightburn", "12345" }, new[] { "Jake McCalvey", "11111" }, new[] { "Paul Jobling", "22222" }, new[] { "John Deary", "33333" }, new[] { "Michael Humphreys", "44444" } };
            int count = 0;
            
            //private
            string password = mtbPassword.Text;
            string username = cbxUsername.Text;
            bool valid = false;

            foreach (string[] s in userList)
            {
                if (username != s[0] || password != s[1]) continue;
                valid = true;
                break;
            }
            if (valid)
            {
                //successfully logged in
            }
            else if (count < 3)
            {
                count++;
            }
            else
            {
                //exit application
            }
 
You are a magician! thanks a lot for help and support. I got told theres a lot of groups where people actually like to fix code, just like p-chan did for me :) and others

Do users generally get this much help or can you reccomend me more places?

Thanks a lot it works a treat :)
 
I think that most people enjoy solving these little problems to be honest. The only thing that some object to is doing the work for others. As long as you have made an effort on your own you will find that 99% of people are happy to help.
 
Ok thanks a lot, ye as you probably seen i had made an effort it was simply the fact i knew what i wanted i just didnt have the knowledge of code to get it working :P

Thanks for formatting above il make sure to use the code tags as its a lot clearer
 
Back
Top Bottom