public static User Login(string email, string password) { try { User user = null; password = MD5Encrypt.GetMd5(password); SqlConnection con = DatabaseFactory.GetConnection(DatabaseFactory.SQL_TYPE_MSSQL).GetConnection(); SqlCommand command = new SqlCommand(); command.Connection = con; command.CommandText = "LoginPROC"; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@email_login", email); command.Parameters.AddWithValue("@password_login", password); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { user = new User(); user.UserEmail = reader.GetString(0); user.UserID = reader.GetInt32(1); user.Firstname = reader.GetString(2); user.Lastname = reader.GetString(3); user.Status = reader.GetInt32(4); user.Username = reader.GetString(5); user.DateRegister = reader.GetDateTime(6); } return(user); } catch (Exception ex) { throw ex; } }
public User(string email, string password) { this.userEmail = email; this.password = MD5Encrypt.GetMd5(password); this.status = STATUS_ACTIVE; this.dateRegister = DateTime.Now; this.userDataAccess = new UserDAO(this); }
public bool ChangePassword(string newPassword) { try { newPassword = MD5Encrypt.GetMd5(newPassword); SqlCommand command = new SqlCommand(); command.Connection = this.connectionForAccess; command.CommandText = "ChangePassword"; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@password_login", this.userForAccess.Password); command.Parameters.AddWithValue("@email_login", this.userForAccess.UserEmail); command.Parameters.AddWithValue("@new_password", newPassword); return(command.ExecuteNonQuery() == 1); } catch (Exception ex) { throw new Exception("User ID wrong, please check again !!!!! "); } }