User.Cscs
public bool AuthenticateUser()
{
string query = "SELECT * FROM users WHERE user_name = @userName LIMIT 1";
bool password = false;
try
{
Console.Write("connection");
using (MySqlConnection connection = Connection.GetConnection())
{
Console.Write("Cmd");
using (var cmd = new MySqlCommand(query, connection))
{
cmd.Parameters.AddWithValue("@userName", this.UserName);
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
password = BCrypt.Net.BCrypt.Verify(this._password + reader["salt"].ToString(), reader["password"].ToString());
this._user_id = int.Parse(reader["id"].ToString());
}
}
}
}
}
catch (MySqlException ex)
{
throw new ArgumentException(ex.Message);
}
catch (Exception ex) {
throw new ArgumentException(ex.Message);
}
return password;
}
I didn't created a method to dispose/close the connection anymore, since as far as I know, the using statement automatically disposes the type of IdisposableIDisposable. I was looking for a suggestion before I continue coding for more functionalities.