private void LogInToolStripMenuItem_Click(object sender, EventArgs e) { using (Form_log_in form_login = new Form_log_in()) { if (form_login.ShowDialog() != DialogResult.OK) { return; } Program.System_user = new User(form_login.Username); if (Program.System_user.UserID == 1) { // temporary for development // if user log in as admin, assign all permissions. just in case any permission not assigned Datasets.Permission_ds.Assign_all_permission_to_administrator(); // developer is only availabe to user id 1 Program.System_user.IsDeveloper = form_login.IsDeveloper; } Setup_menustrip(); ssl_username.Text = Program.System_user.Username; ssl_usergroup.Text = Program.System_user.UserGroup; log_in_menustrip.Visible = false; main_menu_strip.Visible = true; } }
private void Btn_register_Click(object sender, EventArgs e) { if (!Program.System_user.Has_permission(Class_enum.User_permission.ADD_USER)) { MessageBox.Show("You do not have permission to add users!", "ACCESS DENIED", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } Username = txt_username.Text.Trim(); string str_password = txt_pw1.Text; string str_name = txt_fullname.Text.Trim(); string str_ic_no = txt_ic_no.Text.Trim(); if (Username.Length == 0) { MessageBox.Show("Username is required.", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (str_password.Length == 0) { MessageBox.Show("Password is required.", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (str_name.Length == 0) { MessageBox.Show("Full name is required.", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Classes.User.Is_username_valid(Username)) { MessageBox.Show("Username is invalid. Only aphanumeric characters allowed for username. Please retry", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Classes.User.Is_username_available(Username)) { MessageBox.Show("Username is taken.", "Username taken", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Datasets.User_ds.Insert_user(Username, str_name, Form_log_in.ComputeHash(str_password, null), str_ic_no, dtp_join_date.Value); this.DialogResult = DialogResult.OK; this.Close(); }
private void Btn_ok_Click(object sender, EventArgs e) { if (txt_new_pw.Text.Length == 0) { MessageBox.Show("New password cannot be empty.", "Input invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Form_log_in.VerifyHash(txt_old_pw.Text, Program.System_user.Password)) { MessageBox.Show("Old password entered is invalid.", "Denied", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } User_ds.Update_user_password(Form_log_in.ComputeHash(txt_new_pw.Text, null)); MessageBox.Show("Password successfully changed."); this.DialogResult = DialogResult.OK; this.Close(); }