验证码方案MySecurityCode robbin
import java.util.Random;
/**
* @
* SecurityCode的获取
* @author robbin
*
*/
public class SecurityCode {
//验证码方案
public static final int STYLE_NUM = 0;
public static final int STYLE_NUM_LETTER =1;
public static final int STYKE_LETTER =2;
public static String getStr(int style) {
String num = "0123456789";
String letter ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
StringBuffer sb = new StringBuffer();
Random random = new Random() ;
int index;
for (int i = 1; i <= 4; i++) {
if(style ==0){
index = random.nextInt(num.length());
sb.append(num.substring(index, index + 1));
}else if(style == 1){
if (i == 1|| i == 3) {
index = random.nextInt(num.length());
sb.append(num.substring(index, index + 1));
} else {
index = random.nextInt(letter.length());
sb.append(letter.substring(index, index + 1));
}
}else if (style ==2){
index = random.nextInt(letter.length());
sb.append(letter.substring(index, index + 1));
}
}
return sb.toString();
}
}