Beispiel #1
0
 public Account ToAccount()
 {
     Account account = new Account();
     account.Name = this.Username;
     account.Email = this.Email;
     account.Password = this.Password;
     return account;
 }
Beispiel #2
0
 private Account ReadAccount(SQLiteDataReader reader)
 {
     Account account = new Account();
     account.ID = reader.GetInt32(0);
     account.Name = reader.GetString(1);
     account.Email = reader.GetString(2);
     account.Password = reader.GetString(3);
     account.PasswordSalt = reader.GetString(4);
     //account.Score = reader.GetInt32(5);
     account.Timestamp = reader.GetDateTime(6);
     return account;
 }
Beispiel #3
0
 public void Update(Account account)
 {
     try
     {
         using (SQLiteConnection sqliteConnection = new SQLiteConnection(this.connectionString))
         {
             sqliteConnection.Open();
             SQLiteCommand sqlCommand = new SQLiteCommand(SQLiteDataRepository.SQL_ACCOUNT_UPDATE, sqliteConnection);
             sqlCommand.Parameters.AddWithValue("@Name", account.Name);
             sqlCommand.Parameters.AddWithValue("@Email", account.Email);
             sqlCommand.Parameters.AddWithValue("@Password", account.Password);
             sqlCommand.Parameters.AddWithValue("@PasswordSalt", account.PasswordSalt);
             sqlCommand.ExecuteNonQuery();
         }
     }
     catch (Exception exception)
     {
     }
 }
Beispiel #4
0
        public Account GetAccountForEmail(string email)
        {
            try
            {
                Account account = new Account();
                using (SQLiteConnection sqliteConnection = new SQLiteConnection(this.connectionString))
                {
                    sqliteConnection.Open();
                    SQLiteCommand sqlCommand = new SQLiteCommand(SQLiteDataRepository.SQL_ACCOUNT_SELECT_BY_EMAIL, sqliteConnection);
                    sqlCommand.Parameters.AddWithValue("@Email", email);

                    using (SQLiteDataReader reader = sqlCommand.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            account = ReadAccount(reader);
                        }
                    }
                }
                return account;
            }
            catch (Exception exception)
            {
                return null;
            }
        }
Beispiel #5
0
        public Account GetAccount(string accountName)
        {
            try
            {
                Account account = new Account();
                using (SQLiteConnection sqliteConnection = new SQLiteConnection(this.connectionString))
                {
                    sqliteConnection.Open();
                    SQLiteCommand sqlCommand = new SQLiteCommand(SQLiteDataRepository.SQL_ACCOUNT_SELECT_BY_NAME, sqliteConnection);
                    sqlCommand.Parameters.AddWithValue("@Name", accountName);

                    using (SQLiteDataReader reader = sqlCommand.ExecuteReader())
                    {
                        //
                        // Read the first record only
                        //
                        if (reader.Read())
                        {
                            account = ReadAccount(reader);
                        }
                    }
                }
                return account;
            }
            catch (Exception exception)
            {
                return null;
            }
        }
Beispiel #6
0
        public Account Add(Account account)
        {
            try
            {
                using (SQLiteConnection sqliteConnection = new SQLiteConnection(this.connectionString))
                {
                    sqliteConnection.Open();
                    SQLiteCommand sqlCommand = new SQLiteCommand(SQLiteDataRepository.SQL_ACCOUNT_INSERT, sqliteConnection);
                    sqlCommand.Parameters.AddWithValue("@Name", account.Name);
                    sqlCommand.Parameters.AddWithValue("@Email", account.Email);
                    sqlCommand.Parameters.AddWithValue("@Password", account.Password);
                    sqlCommand.Parameters.AddWithValue("@PasswordSalt", account.PasswordSalt);
                    sqlCommand.Parameters.AddWithValue("@Timestamp", account.Timestamp);
                    object returnValue = sqlCommand.ExecuteScalar();

                    int id = int.Parse(returnValue.ToString());
                    account.ID = id;
                }

                return account;
            }
            catch (Exception exception)
            {
                return null;
            }
        }
Beispiel #7
0
        private void Login(Account account)
        {
            if (account != null && account.ID >= 0)
            {
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                    account.Name,
                    DateTime.Now,
                    DateTime.Now.AddDays(30),
                    true,
                    account.ID.ToString(),
                    FormsAuthentication.FormsCookiePath);

                // Encrypt the ticket.
                string encTicket = FormsAuthentication.Encrypt(ticket);

                // Create the cookie.
                Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
            }
        }