Is it possible to delete the row after the time ended? I have a query that going to insert the token then after amount of time, if its not used. The row token will be delete.
Here's how I only created my generator and connect to ajax to sql for now:
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
}
return result;
}
const resulting = makeid(10)
console.log(resulting)
I used a javascript function connected to an ajax to insert the token to its owner.
Here's my query:
string command1 = "insert into account_token(email, token) values (@email, @token)";
using(var cmd1 = new SqlCommand(command1, con)) {
cmd1.Parameters.AddWithValue("@email", email);
cmd1.Parameters.AddWithValue("@token", token);
cmd1.CommandTimeout = 60;
cmd1.ExecuteNonQuery();
con.Close();
}
so basically the "insert into account_token(email, token) values (@email, @token)"
in is:
INSERT INTO account_token(email, token) VALUES ('THE_EMAIL', 'THE_RANDOM_GENERATED_TOKEN')
Is using Date.now() is going to solve my problem?
PS: I'am using asp.net c#
Add Expiretime Column in account_token You could create a SQL Job to run each day and execute a specified stored procedure for delete Expired Tokens