Esempio n. 1
0
        public void onSaveBtnClicked(object sender, RoutedEventArgs e)
        {
            SQLiteDbHelper sqLiteDbHelper = SQLiteDbHelper.getInstance();
            String         passwordText   = this.getPasswordFieldText();

            byte[] salt              = CryptoHelper.generateSalt();
            String saltString        = Convert.ToBase64String(salt);
            String encryptedPassword = CryptoHelper.EncryptStringAES(passwordText, hash, salt);

            if (this.currentState == State.Add)
            {
                sqLiteDbHelper.insert(this.userId, titleField.Text, usernameField.Text, encryptedPassword, saltString);
            }
            else
            {
                AccountDetails updatedAccountDetails = new AccountDetails(this.accountDetails.Id, titleField.Text, usernameField.Text, encryptedPassword, saltString);
                sqLiteDbHelper.update(updatedAccountDetails, this.userId);
            }

            this.Close();
        }
        public AccountDetails selectWithId(long id, long userId)
        {
            this.dbConnection.Open();

            SQLiteCommand command = new SQLiteCommand(this.select_account_with_id, dbConnection);

            command.Parameters.Add(new SQLiteParameter("@id", id));
            command.Parameters.Add(new SQLiteParameter("@user_id", userId));
            SQLiteDataReader reader         = command.ExecuteReader();
            AccountDetails   accountDetails = new AccountDetails();

            while (reader.Read())
            {
                accountDetails.Id                = (long)reader["id"];
                accountDetails.Title             = (String)reader["title"];
                accountDetails.Username          = (String)reader["username"];
                accountDetails.EncryptedPassword = (String)reader["encrypted_password"];
                accountDetails.Salt              = (String)reader["salt"];
            }
            this.dbConnection.Close();
            return(accountDetails);
        }