private void bLogin_Click(object sender, EventArgs e) { string loginUser = tbLogin.Text; string passwordUser = tbPassword.Text; FirstOpen firstOpen = new FirstOpen(); firstOpen.CreateUsersIfNotExit(); PassChange passChange = new PassChange(); if (passChange.CheckPass(loginUser, passwordUser) == false) { MessageBox.Show("Ошибка в пароле или логине"); return; } this.Hide(); if (loginUser != "admin") { TextEncrypter textEncrypter = new TextEncrypter(); textEncrypter.username = tbLogin.Text; textEncrypter.admin = false; textEncrypter.Show(); return; } else { Admin admin = new Admin(); this.Hide(); admin.Show(); return; } }
private void ibOpen_Click_1(object sender, EventArgs e) { if (lbUsers.SelectedItem == null) { return; } TextEncrypter textEncrypter = new TextEncrypter(); textEncrypter.username = Convert.ToString(lbUsers.SelectedItem); textEncrypter.admin = true; textEncrypter.Show(); this.Hide(); }
private void bRegister_Click(object sender, EventArgs e) { DB db = new DB(); string login = tbLogin.Text; string password = tbPassword.Text; if (login == "") { MessageBox.Show("Введите логин"); return; } if (password == "") { MessageBox.Show("Введите пароль"); return; } if (isUserExists()) { MessageBox.Show("Пользователь с таким логином уже существует, введите другой."); return; } SQLiteCommand command = new SQLiteCommand("INSERT INTO users(login, password, cryptokey) VALUES(@login, @password, @cryptokey)", db.getConnection()); //для шифрования пароля Crypt crypt = new Crypt(); string key = crypt.GenerateKey(); string hash = crypt.GetHash(password); command.Parameters.AddWithValue("@login", login).Size = 50; command.Parameters.AddWithValue("@password", crypt.CryptStr(hash, key)).Size = 50; command.Parameters.AddWithValue("@cryptokey", key).Size = crypt.keyLength; SQLiteCommand command2 = new SQLiteCommand($"CREATE TABLE {login} (docname nvarchar(50) NOT NULL, doc ntext NOT NULL);", db.getConnection()); db.openConnection(); if (command.ExecuteNonQuery() == 1) { command2.ExecuteNonQuery(); MessageBox.Show("Аккаунт успешно создан"); } else { MessageBox.Show("Произошла ошибка"); } db.closeConnection(); this.Hide(); if (login == "admin") { Admin admin = new Admin(); admin.Show(); return; } TextEncrypter textEncrypter = new TextEncrypter(); textEncrypter.username = login; if (login != "admin") { textEncrypter.admin = false; } textEncrypter.Show(); }