Dynamic login

description:to generate a dynamic login password and approve the user's password is same with the dynamic one.The verification process is mainly finished in .html file by JavaScript functions.

firstly:to generate a random number with a given range[1000,9999](four numbers)

<script>
function generateRandom(){
var result=1000+Math.floor(Math.random()*8999);
return result;
}
</script>

second step:show the number on the webpage

<script>var print=generateRandom();</script>

<table bgcolor="#000000" style="color: white">
<tr>
<td><script>document.write(print);</script></td>
</tr>
</table>

third:certificate function

<script>
function approve(){
var x=document.getElementById("number").value;
if(!(x==print)){
alert("Input number is wrong.");
return false;
}
return true;
}
</script>

the usage in the form:

<form method="post" action="DynamicApprove" onsubmit="return approve()">
<p>input the number you see:<br><input type="text" id="number" name ="lena" size="25" maxlength="16"></p>
<input type="submit" value="submit">
</form>

It comes to the end.You can test it with your IDEA.

原文地址:https://www.cnblogs.com/ssMellon/p/6671483.html