public static bool SaveUser(string username, string fullnames, string password, string secque, string answer, string email, string telephone) { try { SkypensionCryptoEngine _SkypensionCryptoEngine = new SkypensionCryptoEngine(); var _User = new User(); _User.UserName = username; _User.FullNames = fullnames; _User.Password = SkypensionCryptoEngine.Encrypt(password, true); _User.Question = secque; _User.Answer = answer; _User.Email = email; _User.Telephone = telephone; if (_User.SaveUser()) { return(true); } else { return(false); } } catch (Exception ex) { var _Security = new Security(); _Security.ErrorDesscription = ex.Message; _Security.ErrorModule = "Intializing saving user"; _Security.SaveError(); return(false); } }
public bool ValidateUser() { try { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString)) { using (SqlCommand SqlCommand = new SqlCommand("spValidateUser", con)) { ds = new DataSet("Users"); SqlCommand.CommandType = CommandType.StoredProcedure; SqlCommand.Parameters.Clear(); SqlCommand.Parameters.AddWithValue("@UserName", UserName); if (con.State == ConnectionState.Closed) { con.Open(); } SQAdapter.SelectCommand = SqlCommand; SQAdapter.Fill(ds, "Users"); if (ds.Tables["Users"].Rows.Count > 0) { String CipherString = (ds.Tables["Users"].Rows[0]["Password"]).ToString(); if (SkypensionCryptoEngine.Decrypt(CipherString, true).Equals(Password)) { return(true); } } return(false); } } } catch (Exception) { return(false); } }
public bool ValidateUser() { try { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString)) { using (SqlCommand SqlCommand = new SqlCommand("spValidateUser", con)) { DataSet ds = new DataSet("Users"); SqlCommand.CommandType = CommandType.StoredProcedure; SqlCommand.Parameters.Clear(); SqlCommand.Parameters.AddWithValue("@UserName", UserName); if (con.State == ConnectionState.Closed) { con.Open(); } SQAdapter.SelectCommand = SqlCommand; SQAdapter.Fill(ds, "Users"); if (ds.Tables["Users"].Rows.Count > 0) { String CipherString = (ds.Tables["Users"].Rows[0]["Password"]).ToString(); if (SkypensionCryptoEngine.Decrypt(CipherString, true).Equals(Password)) { UserNameCookie.Value = this.UserName; HttpContext.Current.Response.Cookies.Add(UserNameCookie); return(true); } } return(false); } } } catch (Exception ex) { Security secs = new Security(); secs.ErrorDesscription = ex.Message; secs.Terminus = Environment.MachineName; secs.ErrorModule = "Validating User-Login"; secs.SaveError(); throw (ex); //return false; } }
private void saveToolStripButton_Click(object sender, EventArgs e) { try { if (this.ValidateRight("Add", AppConstant.UserID)) { var password = PasswordTextEdit.Text.ToString(); var ConfirmPassword = ConfirmPasswordTextEdit.Text.ToString(); if (password == ConfirmPassword) { this.spSelectUsersTableAdapter.spSaveUsers( AppConstant.CompCode, UserNameTextEdit.Text.ToString(), FullNamesTextEdit.Text.ToString(), SkypensionCryptoEngine.Encrypt(password, true), SkypensionCryptoEngine.Encrypt(ConfirmPassword, true), EmailTextEdit.Text.ToString(), TelephoneTextEdit.Text.ToString(), ExpiryDateDateEdit.DateTime, IsActiveCheckEdit.Checked, SuperUserCheckEdit.Checked, CCCodeTextEdit.EditValue.ToString(), NarrationTextEdit.Text.ToString(), Environment.MachineName, AppConstant.UserID ); MessageBox.Show("User saved successfully"); this.spSelectAllUsersTableAdapter.Fill(this.dsUsers.spSelectAllUsers, AppConstant.CompCode, AppConstant.UserID, Environment.MachineName); } else { MessageBox.Show("Sorry, your passwords don't match"); } } else { MessageBox.Show("Privilege Violation.You have insufficient right to add Users", "Privilege Violation", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }