private void CreateUser() { string s = AccessOperation.EncryptPassword(textbox_5.Text); Worker newWorker = new Worker() { FirstName = textbox_1.Text, LastName = textbox_2.Text, Email = textbox_3.Text, Manager = false, UserLogin = textbox_4.Text, UserPassword = s, Type = 'U' }; contextDC.Worker.InsertOnSubmit(newWorker); contextDC.SubmitChanges(); string info = "Registration Successfully"; CustomDialog RegistrationSucessfully = new CustomDialog(info, 1); RegistrationSucessfully.ShowDialog(); ChangeFunction(); }
private void LoginToApp() { try { // check password string s; s = AccessOperation.EncryptPassword(textbox_2.Text); var usr = contextDC.Worker.Where(c => c.UserLogin == textbox_1.Text && c.UserPassword == s).Single(); if (usr != null) { User user = new User(usr.Id, usr.Type, usr.UserLogin); ClearButtons(); MainMenu main_menu = new MainMenu(user); main_menu.Show(); this.Hide(); } } catch (Exception) { ClearButtons(); string error = "Username or Password is invaild !\nPlease try again."; CustomDialog Error = new CustomDialog(error, 1); Error.ShowDialog(); } }
// Save info to database private void SaveToDB(int EditOrAdd) { string s = ""; Worker WorkerToSave = null; if (EditOrAdd == 1) { // Add WorkerToSave = new Worker(); contextDB.Worker.InsertOnSubmit(WorkerToSave); s = AccessOperation.EncryptPassword(textBox6.Text); WorkerToSave.UserPassword = s; WorkerToSave.Type = 'U'; } else if (EditOrAdd == 2) { // Edit WorkerToSave = listOfWorkers.SelectedItem as Worker; } WorkerToSave.FirstName = textBox1.Text; WorkerToSave.LastName = textBox2.Text; WorkerToSave.Email = textBox3.Text; WorkerToSave.UserLogin = textBox4.Text; WorkerToSave.Manager = checkBox1.Checked; contextDB.SubmitChanges(); LoadData(); DataChangeOff(); }
private void CheckPasswords() { if (Choice == 1) { string s = ""; string g = ""; string ErrorText = ""; CustomDialog ErrorForm = null; if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text)) { ErrorText = "Make sure you fill in all the fields"; ErrorForm = new CustomDialog(ErrorText, 1); ErrorForm.ShowDialog(); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); } else { // sprawdz czy podane haslo jest takie samo jak w bazie danych Worker WorkerToSave = listOfWorkers.SelectedItem as Worker; s = AccessOperation.EncryptPassword(textBox1.Text); var usr = contextDB.Worker.Where(c => c.UserLogin == WorkerToSave.UserLogin && c.UserPassword == s).SingleOrDefault(); if (usr != null) { if (textBox2.Text != textBox3.Text || textBox2.Text == textBox1.Text) { ErrorText = "Check if your new password was entered correctly 2 times and if it differs from the old one"; ErrorForm = new CustomDialog(ErrorText, 1); ErrorForm.ShowDialog(); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); } else if (textBox2.Text != textBox1.Text && textBox2.Text == textBox3.Text) { g = AccessOperation.EncryptPassword(textBox2.Text); WorkerToSave.UserPassword = g; contextDB.SubmitChanges(); if (x.Count != 0) { SearchNextB.Enabled = true; SearchPreviousB.Enabled = true; } textBox1.PasswordChar = '\0'; textBox2.PasswordChar = '\0'; textBox3.PasswordChar = '\0'; DataChangeOff(); } } else { ErrorText = "To change the password you must enter the correct one first"; ErrorForm = new CustomDialog(ErrorText, 1); ErrorForm.ShowDialog(); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); } } } }