Expiring user usage time Mysql

0

I'm doing a C # sign-in system where the user is logged in to verify their login, password and how much time they have left to use the system. Even the part of checking login and password I managed to do, but I'm having trouble checking the usage time. For example, it can not use when a certain date arrives.

Follow my code here:

try
{
    string sql = "SELECT * FROM users WHERE userName = @login AND userPass  = @senha ";

    MySqlConnection con = new MySqlConnection("host=; user=; password=; database=; Port=3306;");
    MySqlCommand cmd = new MySqlCommand(sql, con);

    cmd.Parameters.AddWithValue("@login", this.usuario.Text);
    cmd.Parameters.AddWithValue("@senha", this.senha.Text);

    con.Open();

    int a = (int)cmd.ExecuteScalar();

    if (a > 0)// caso login e senha e tempo de uso OK
    {
        Form1 segundo = new Form1();
        this.Hide();
        segundo.ShowDialog();
    }
    else
    {
        MessageBox.Show("Seu tempo de uso acabou");
    }

}
catch 
{
    MessageBox.Show("User or Pass Incorrect!");
    usuario.Text = "";
    senha.Text = "";
}

In my database I have the following fields: userID, userName, userPass, DateExpiration

Simulating a situation, the user was registered today and can only log in until 02/25/2017. I want it on 2/26/2017 that he can not log in anymore.

    
asked by anonymous 24.02.2017 / 13:25

1 answer

1

While maintaining the logic of your implementation, you can declare your SQL statement like this:

string sql = "SELECT * FROM users WHERE userName = @login AND userPass  = @senha AND DateExpiration >= DATE(@dataAtual)";

And "sign" the parameters like this:

cmd.Parameters.AddWithValue("@login", this.usuario.Text);
cmd.Parameters.AddWithValue("@senha", this.senha.Text);
cmd.Parameters.AddWithValue("@dataAtual", DateTime.Today);
    
24.02.2017 / 14:02