private static string GetDecryptedPassword(string user = "") { using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) { var output = cnn.Query <UserModel>("SELECT * FROM User WHERE Username = '******'", new DynamicParameters()); List <UserModel> listUser = output.ToList(); UserModel userModel; string Password = ""; if (listUser.Count > 0) { userModel = listUser[0]; LoginForm.userModel = userModel; Password = EncryptPassword.Decrypt(userModel.Password, "zxc123"); } return(Password); } }
public static void AddUser(UserModel user) { string password = EncryptPassword.Encrypt(user.Password, "zxc123"); using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) { if (CheckIfUserExist(user) > 0) { System.Windows.Forms.MessageBox.Show("Username sudah ada!", "Error", System.Windows.Forms.MessageBoxButtons.OK); } else { cnn.Execute("INSERT INTO User (Username, Password, Nama, Jabatan, Instalasi, Role) " + "VALUES (@Username, '" + password + "', @Nama, @Jabatan, @Instalasi, @Role)", user); } } }
void initUserTable() { ut = new DataTable(); ut.Columns.Add("no", typeof(int)); ut.Columns.Add("user", typeof(string)); ut.Columns.Add("pass", typeof(string)); ut.Columns.Add("nama", typeof(string)); ut.Columns.Add("jabatan", typeof(string)); ut.Columns.Add("instalasi", typeof(string)); ut.Columns.Add("role", typeof(int)); int count = 0; AppForm.listUser = SqliteDataAccess.loadUser(); foreach (UserModel user in AppForm.listUser) { count++; ut.Rows.Add(count, user.Username, EncryptPassword.Decrypt(user.Password, "zxc123"), user.Nama, user.Jabatan, user.Instalasi, user.Role); } dataGridView1.DataSource = ut; }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } if (e.ColumnIndex == dataGridView1.Columns["updateButton"].Index) { UserModel newUser = new UserModel(); newUser.Username = (string)dataGridView1.Rows[e.RowIndex].Cells[3].Value; newUser.Password = EncryptPassword.Encrypt((string)dataGridView1.Rows[e.RowIndex].Cells[4].Value, "zxc123"); newUser.Nama = (string)dataGridView1.Rows[e.RowIndex].Cells[5].Value; newUser.Jabatan = (string)dataGridView1.Rows[e.RowIndex].Cells[6].Value; newUser.Instalasi = (string)dataGridView1.Rows[e.RowIndex].Cells[7].Value; newUser.Role = (int)dataGridView1.Rows[e.RowIndex].Cells[8].Value; SqliteDataAccess.UpdateUser(ut.Rows[e.RowIndex][1].ToString(), newUser); } if (e.ColumnIndex == dataGridView1.Columns["deleteButton"].Index) { SqliteDataAccess.DeleteUser((string)dataGridView1.Rows[e.RowIndex].Cells[3].Value); dataGridView1.Rows.RemoveAt(e.RowIndex); initUserTable(); } }