验证码技术是网站开放过程中该保护网站安全的最基本环节,它可以防止非法人员利用注册工具或登录工具来攻击网站(也就是常说的灌水),从而保护网站安全。

话不多说,直接上代码:
package com.wgh.random;
public class RanDom {
private String checknum=""; //生成的验证码
private int number=0; //用户输入的位数
public RanDom(){}
public void setNumber(int number){
this.number=number;
}
public int getNumber(){
return this.number;
}
public void makeChecknum(){
String sourcenum="0123456789"; //定义获取随机数的源字符串
String siglenum=""; //保存获取到的单个随机数
String checknum=""; //获取到的随机数
int index=0; //获取随机数的位置
int i=0;
while(i<this.number index="((int)(Math.random()*100))%(sourcenum.length()-1);" siglenum="sourcenum.substring(index,index+1);" checknum i this.checknum="checknum;" public return><p><strong>dorandomnum.jsp:</strong><br></p>
<pre class="brush:php;toolbar:false;">
<usebean></usebean>
<title>随机产生指定位数的验证码</title>
<link>
<center>
<table>
<tr>
<td>生成的验证码</td>
</tr>
<tr>
<td>
验证码的位数:
<br>
生成的验证码:
</td>
</tr>
</table>
<a>[返回]</a>
</center>
index.jsp:
<title>随机产生指定位数的验证码</title> <link> <center> <form> <table> <tr> <td>随机产生指定位数的验证码</td> </tr> <tr> <td> 输入验证码位数: <input> <input> </td> </tr> </table> </form> </center>
相关推荐:











