I have a class that determines the user type
public class Auth
{
public enum UserType : ushort
{
Admin = 0,
User = 1,
None = 2,
}
public UserType userType = UserType.None;
private Dictionary<string, string> users;
public Auth()
{
}
public Auth(string login, string password)
{
users = new Dictionary<string, string>();
users.Add( "admin", "global");
users.Add("user", "client");
if (!users.ContainsKey(login))
{
if (users[password] == users[login])
{
if (users[login] == "admin")
userType = UserType.Admin;
else if (users[login] == "user")
userType = UserType.User;
else
userType = UserType.None;
}
}
else
userType = UserType.None;
And I have a form where login and password are entered. When you enter the correct login and password, the program incorrectly determines the user type and displays MessageBox("wrong login or password ")
public partial class FormAuth : Form
{
private FormMain main;
private Auth auth;
public FormAuth(FormMain main)
{
this.main = main;
InitializeComponent();
this.textBoxPassword.PasswordChar = '*';
auth = new Auth();
}
private void buttonLogIn_Click(object sender, EventArgs e)
{
auth = new Auth(textBoxLogin.Text, textBoxPassword.Text);
if (auth.userType == Auth.UserType.None)
{
MessageBox.Show("wrong login or password");
textBoxPassword.Text = "";
textBoxPassword.Focus();
}
else
{
main.userType = auth.userType;
this.Close();
}
}
I've tried redoing the code, but I can't seem to fix it. Tell me the mistake please