private void BtnAdminPanel_Click(object sender, EventArgs e) { AdminPanelForm adm = new AdminPanelForm(); LoginForm lf = new LoginForm(); if (lf.ShowDialog() == DialogResult.OK) { if (adm.ShowDialog() == DialogResult.OK) { } } }
private void Btn_login_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtBoxPassword.Text)) { string loginUser = txtBoxUser.Text; string passUser = txtBoxPassword.Text; var user = GetUserByEmail(loginUser); if (loginUser == "admin") { if (passUser == "admin") { AdminPanelForm adp = new AdminPanelForm(); adp.ShowDialog(); } } else if (user != null || loginUser == "noconnection") { if (loginUser == "noconnection") { ChangeAccSettingForm casf = new ChangeAccSettingForm(); if (casf.ShowDialog() == DialogResult.OK) { } } else if (user.Deleted == false) { ICryptoService cryptoService = new PBKDF2(); string salt = user.PasswordHash; string hashPassword2 = cryptoService.Compute(passUser, salt); bool isPasswordValid = cryptoService.Compare(user.Password, hashPassword2); if (isPasswordValid) { MessageBox.Show("You login success", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); ChangeAccSettingForm casf = new ChangeAccSettingForm(); casf.FillForm(user); casf.FillLoginUser(user); if (casf.ShowDialog() == DialogResult.OK) { if (casf.IsDel) { user.Deleted = true; } if (casf.FirstName != null && casf.FirstName != user.FirstName) { user.FirstName = casf.FirstName; } if (casf.FileSelect != null && casf.FileSelect.ToString() != user.UserImage.ToString()) { //string extension = Path.GetExtension(casf.FileSelect); //string nameFile = Path.GetRandomFileName() + extension; //var path = Path.Combine(Directory.GetCurrentDirectory(), // "user_images", Path.GetFileName(casf.FileSelect)); //var bmp = ImageHelper.ComprressImage(Image.FromFile(casf.FileSelect), 120, 80); //try //{ // bmp.Save(path, ImageFormat.Jpeg); //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} user.UserImage = casf.ImageToByteArray(Image.FromFile(casf.FileSelect)); } if (casf.LastName != null && casf.LastName != user.LastName) { user.LastName = casf.LastName; } if (casf.MobilePhone != null && casf.MobilePhone != user.MobilePhoneNumber) { user.MobilePhoneNumber = casf.MobilePhone; } if (casf.Password != "") { ICryptoService new_cryptoService = new PBKDF2(); //New User string new_password = casf.Password; //save this salt to the database string new_salt = cryptoService.GenerateSalt(); //save this hash to the database string new_hashedPassword = cryptoService.Compute(new_password); user.Password = new_hashedPassword; user.PasswordHash = new_salt; } context.SaveChanges(); } } else { MessageBox.Show("Inccorect login or password!", "Please try again!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("This account not exist or be deleted!"); } } else { MessageBox.Show("Inccorect login or password!", "Please try again!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.Close(); }
private void HeadeMenu_Data_AdminPanel_Click(object sender, EventArgs e) { AdminPanelForm apf = new AdminPanelForm(); apf.ShowDialog(); }