public static User AuthorizeUser(User user) { if (!isConnected) { Init(); } SQLiteCommand sqliteCommand = dbConnection.CreateCommand(); sqliteCommand.Parameters.Add( new SQLiteParameter( ":userName", user.username ) ); sqliteCommand.CommandText = "SELECT * FROM " + USERS_TABLE + " WHERE userName=:userName"; SQLiteDataReader sqliteReader = sqliteCommand.ExecuteReader(); // if user already exist if ( sqliteReader.HasRows ) { if ( sqliteReader["password"].ToString() == user.password ) { user.action = User.AUTH; } else { user.action = User.EXIST; } } else { user.action = User.EXIST; } return user; }
private void AuthorizeUser() { User user = new User(); user.username = nameField.Text; user.password = passwordField.Text; if (confirmField.Visible) { if (passwordField.Text == confirmField.Text) { user = PollClientGUI.pollService.RegisterUser(user); switch (user.action) { case User.AUTH: PollClientGUI.isAuthorized = true; PollClientGUI.userName = nameField.Text; Close(); return; case User.EXIST: MessageBox.Show("Error occured during registation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("\"password\" and \"confirm password\" fields aren't identicals", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } user = PollClientGUI.pollService.ExistUser(user); if (user.action == User.EXIST) { user = PollClientGUI.pollService.AuthorizeUser(user); switch (user.action) { case User.AUTH: PollClientGUI.isAuthorized = true; PollClientGUI.userName = nameField.Text; Close(); break; case User.EXIST: MessageBox.Show("Wrong password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show("User not found in DB, program will create a new user", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); confirmField.Visible = true; confirmLabel.Visible = true; nameField.Enabled = false; this.Size = new Size(234, 150); submitButton.Top = 85; settingsButton.Top = 85; } }
public User AuthorizeUser(User user) { if (Authentication.userName == USER_NAME && Authentication.password == PASSWORD) { return DAL.PollDAL.AuthorizeUser(user); } else { return null; } }
public void Login_Click(Object sender, EventArgs e) { Ilsrep.PollApplication.Model.User user = new Ilsrep.PollApplication.Model.User(); user.username = username.Text; user.password = password.Text; user = PollDAL.AuthorizeUser(user); if (user.action == Ilsrep.PollApplication.Model.User.AUTH) FormsAuthentication.RedirectFromLoginPage(username.Text, false); else message.InnerHtml = "Invalid credentials!"; }
public void Register_Click(Object sender, EventArgs e) { if ((regUsername.Text == String.Empty) || (regPassword.Text == String.Empty) || (regConfirmPassword.Text == String.Empty)) { regMessage.InnerHtml = "Please, fill all fields"; return; } if (regPassword.Text != regConfirmPassword.Text) { regMessage.InnerHtml = "Password and Confirm password fields must be the same"; return; } Ilsrep.PollApplication.Model.User user = new Ilsrep.PollApplication.Model.User(); user.username = regUsername.Text; user.password = regPassword.Text; user = PollDAL.ExistUser(user); if (user.action == Ilsrep.PollApplication.Model.User.NEW_USER) { user = PollDAL.RegisterUser(user); if (user.action == Ilsrep.PollApplication.Model.User.AUTH) { FormsAuthentication.RedirectFromLoginPage(regUsername.Text, false); } else { regMessage.InnerHtml = "An undefined error occured in server"; } } else { regMessage.InnerHtml = "Such user already exists"; } }
public static User RegisterUser(User user) { if (!isConnected) { Init(); } try { SQLiteCommand sqliteCommand = dbConnection.CreateCommand(); sqliteCommand.Parameters.Add( new SQLiteParameter( ":userName", user.username ) ); sqliteCommand.Parameters.Add( new SQLiteParameter( ":password", user.password ) ); sqliteCommand.CommandText = "INSERT INTO " + USERS_TABLE + "(userName, password) VALUES (:userName, :password)"; SQLiteDataReader sqliteReader = sqliteCommand.ExecuteReader(); user.action = User.AUTH; } catch (Exception) { user.action = User.EXIST; } return user; }