I want a code to be sent to the user and that code can be used for 3 minutes to log in the user so that the user cannot request a code in these 3 minutes.
I want a code to be sent to the user and that code can be used for 3 minutes to log in the user so that the user cannot request a code in these 3 minutes.
David's advice is very good, you should write the code first and ask questions when you encounter problems.
Regarding your needs, I can provide you with some ideas.
First you need to know that when the browser client connects with the asp.net core webserver, the session ID is generated when the connection is established.
We can customize the code, codeState in session, to determine whether the user who established the connection has logged in.
code string type: 0123 or Az02
codeState null -> not generated
-1 -> expired
0 -> generated but un-use
1 -> used
if(codeState=null){
code = generate_code();
HttpContext.Session.SetString("code",code);
}
if(codeState == -1){
msg = "The code has expired, pls click the button to generate a new code";
}
if(codeState== 0){
msg = "The code has generated";
code = HttpContext.Session.GetString("code");
}
if(codeState== 1){
msg = "The code has used";
}