Ejemplo n.º 1
0
 public static User GetUser(string username, string password)
 {
     using (SqlConnection connection = new SqlConnection())
     {
         connection.ConnectionString = ConfigurationManager.ConnectionStrings["GameLibraryDBCS"].ConnectionString;
         using (SqlCommand command = new SqlCommand())
         {
             command.Connection  = connection;
             command.CommandText = "sp_AuthenticateUser";
             command.CommandType = CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@username", username);
             command.Parameters.AddWithValue("@password", PasswordEncryptSHA256.GenerateSHA256String(password));
             connection.Open();
             using (SqlDataReader dataReader = command.ExecuteReader())
             {
                 if (dataReader.Read())
                 {
                     User user = new User()
                     {
                         id_User          = Convert.ToInt32(dataReader["id_user"]),
                         Username         = dataReader["username"].ToString(),
                         Password         = dataReader["password"].ToString(),
                         Email            = dataReader["email"].ToString(),
                         Role             = dataReader["role"].ToString()[0],
                         isloocked        = Convert.ToBoolean(dataReader["is_looked"]),
                         nr_attempts      = Convert.ToInt32(dataReader["nr_attempts"]),
                         locked_date_time = dataReader["locked_date_time"] == DBNull.Value ? (DateTime?)null : Convert.ToDateTime(dataReader["locked_date_time"])
                     };
                     return(user);
                 }
                 return(null);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public static int UpdatePass(string username, string password)
 {
     using (SqlConnection connection = new SqlConnection())
     {
         connection.ConnectionString = ConfigurationManager.ConnectionStrings["PAP_DBCS"].ConnectionString;
         using (SqlCommand command = new SqlCommand())
         {
             command.Connection  = connection;
             command.CommandText = "sp_UpdatePass";
             command.CommandType = CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@username", username);
             command.Parameters.AddWithValue("@password", PasswordEncryptSHA256.GenerateSHA256String(password));
             connection.Open();
             int returncode = (int)command.ExecuteScalar();
             return(returncode);
         }
     }
 }
Ejemplo n.º 3
0
 public static int ResetPassword(int id_user, string new_password)
 {
     using (SqlConnection connection = new SqlConnection())
     {
         connection.ConnectionString = ConfigurationManager.ConnectionStrings["GameLibraryDBCS"].ConnectionString;
         using (SqlCommand command = new SqlCommand())
         {
             command.Connection  = connection;
             command.CommandText = "sp_ResetPassword";
             command.Parameters.AddWithValue("@id_user", id_user);
             command.Parameters.AddWithValue("@new_password", PasswordEncryptSHA256.GenerateSHA256String(new_password));
             command.CommandType = CommandType.StoredProcedure;
             connection.Open();
             int returncode = (int)command.ExecuteScalar();
             return(returncode);
         }
     }
 }
Ejemplo n.º 4
0
 public static int RegisterUser(User user)
 {
     using (SqlConnection connection = new SqlConnection())
     {
         connection.ConnectionString = ConfigurationManager.ConnectionStrings["GameLibraryDBCS"].ConnectionString;
         using (SqlCommand command = new SqlCommand())
         {
             command.Connection  = connection;
             command.CommandText = "sp_InsertUser";
             command.CommandType = CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@username", user.Username);
             command.Parameters.AddWithValue("@password", PasswordEncryptSHA256.GenerateSHA256String(user.Password));
             command.Parameters.AddWithValue("@email", user.Email);
             command.Parameters.AddWithValue("@role", 'U');
             connection.Open();
             int returncode = (int)command.ExecuteScalar();
             return(returncode);
         }
     }
 }