private void BtnUpdate_Click(object sender, RoutedEventArgs e) { string pswMd5 = null; if (pwdPswOne.Password.Length == 0 || pwdPswTwo.Password.Length == 0) { MessageBox.Show("Please entre new password", "Update error", MessageBoxButton.OK, MessageBoxImage.Error); return; } else if (pwdPswOne.Password != pwdPswTwo.Password) { MessageBox.Show("Password not match, please check again", "Update error", MessageBoxButton.OK, MessageBoxImage.Error); return; } else { using (MD5 md5Hash = MD5.Create()) { pswMd5 = Utiles.GetMd5Hash(md5Hash, pwdPswOne.Password); } if (Globals.currUser != null) { Globals.Db.UpdateUserAccount(Globals.currUser, pswMd5); return; } } if (!Regex.IsMatch(tbUserEmail.Text, @"^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,})$")) { MessageBox.Show("Email format not correct", "Sign up error", MessageBoxButton.OK, MessageBoxImage.Error); return; } else { Globals.Db = new Database(); if (Globals.Db.LoginVerification(tbUserEmail.Text) != null) { MessageBox.Show("User exist, please login in", "Sign up error", MessageBoxButton.OK, MessageBoxImage.Error); return; } else { User newUser = new User() { Username = tbUserName.Text, Email = tbUserEmail.Text, Password = pswMd5 }; newUser.User_id = Globals.Db.NewUserSignUp(newUser); Globals.currUser = newUser; DialogResult = true; } } }
private void UserLogin_ButtonClick(object sender, RoutedEventArgs e) { email = tbUserEmail.Text; password = pwdUserPsw.Password; isRemember = (bool)cbRemenberMe.IsChecked; if (email.Length == 0 || password.Length == 0) { message = "Please entre all the information"; title = "Information not complet"; MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Error); } else if (!Regex.IsMatch(email, @"^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,})$")) { message = "Please check email format"; title = "Information not complet"; MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Error); } else { Globals.currUser = new User(); using (MD5 md5Hash = MD5.Create()) { pswMd5 = Utiles.GetMd5Hash(md5Hash, password); } User user = Globals.Db.LoginVerification(email); if (pswMd5 == user.Password) { Globals.currUser = user; Globals.currUserSub = Globals.Db.GetSubscriptChannels(Globals.currUser); //write to confi if (isRemember) { try { Utiles.AddOrUpdateAppSettings("userEmail", email); Utiles.AddOrUpdateAppSettings("password", pswMd5); Utiles.AddOrUpdateAppSettings("isRemember", "true"); } catch (ConfigurationErrorsException ex) { MessageBox.Show("Cannot remember you login set", "login set error", MessageBoxButton.OK, MessageBoxImage.Error); } } DialogResult = true; } else { message = "Wrong user email or password \n Try again"; title = "HeadLine News Login"; MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Error); } } }