导航:首页 > 编程语言 > 滑动验证码java

滑动验证码java

发布时间:2023-01-30 12:56:23

A. java怎么实现验证码识别

图片验证码是什么
图片验证码,这个大家应该都见过。最普遍的图片验证码就是一张图片上面有4-6个歪歪扭扭的数字字母,图片还有点看不清楚,但是基本可以肉眼识别出上面的数字字母。那为什么要有这个东东呢?

其实验证码的出现为了区分人与机器。对于歪歪妞妞还有点看不清的数字字母图片,由于人脑的特殊构造,是可以完全无障碍识别的,但是想让奇迹识别出这些字母数字,就会出现识别错误。那为什么要区别人与机器呢?假如一个一个系统没有验证码,我知道了你的用户名,并且知道你的登录密码是8位的数字,那我完全可以写个脚本程序穷举出所有的8位数组合,挨个去尝试登录,这个过程对于人来说可能耗时耗力,但是对于程序来说,so easy。所以验证码的出现就会阻止程序进行这样的穷举登录。

随着技术的发展,现在很多的验证码系统都可以通过图像处理、机器学习深度学习等方式进行攻破,图片验证码已经不再安全,即使是非常有名的12306验证码,也已经被利用深度学习达到了很高的识别精度。所以也出现了手机验证码、拖动滑块图片到指定位置的验证码等各种验证码。

B. 往右划的验证码,是在验证什么

目前滑动验证码的功能主要还是增加用户的安全,验证的是这是人为操作还是机器操作,防止一些不法分子利用自动程序恶意注册登录、暴力破解密码以及批量操作(刷单、发帖)等行为。如果没有验证码,暴力破解密码后就可以直接登录,相反,如果设置了验证码,程序很难识别,那么就无法登录成功。除此之外,还可以防止黑客恶意攻击从而导致服务器压力太大而崩溃,比如论坛灌水、刷页、刷票等,有些论坛回复需要输入验证码就是出于这个目的。

3、根据上述收集到相关信息计算滑块移动轨迹并模拟人移动滑块的整个过程。

计算出了滑块移动的轨迹图,接下来就需要模拟人移动滑块的过程。现在的滑动验证码识别安全性很高,绝大多数都加入了机器学习模型,也就是说,人在移动滑块的时候不可能是匀速的。所以说,只是简单的匀速滑动肯定是被认定为机器操作。因此模拟人拖动滑块的过程中需要加入几个过程,比如先加速,再减速,适当加入回退和随机抖动,尽可能的模拟人的行为。滑动的过程可以通过在代码中设置相应变量,再加上相应公式就可以解决,对于专业人员并不复杂。

C. Java如何实现验证码验证功能

Java如何实现验证码验证功能呢?日常生活中,验证码随处可见,他可以在一定程度上保护账号安全,那么他是怎么实现的呢?

Java实现验证码验证功能其实非常简单:用到了一个Graphics类在画板上绘制字母,随机选取一定数量的字母随机生成,然后在画板上随机生成几条干扰线。

首先,写一个验证码生成帮助类,用来绘制随机字母:

接着,创建一个servlet,用来固定图片大小,以及处理验证码的使用场景,以及捕获页面生成的验证码(捕获到的二维码与用户输入的验证码一致才能通过)。

接着写一个HTML注册页面用来检验一下:

效果如下图:



当点击刷新页面的时候,验证码也会随着变化,但我们看不清验证码时,只要点击验证码就会刷新,这样局部的刷新可以用JavaScript来实现。

在<img
src="/demo/verify/regist.do">中,添加一个问号和一串后缀数字,当刷新时让后缀数字不断改变,那么形成的验证码也会不断变化,我们可以采用的一种办法是后缀数字用date代替,date获取本机时间,时间是随时变的,这样就保证了刷新验证码可以随时变化。

代码如下:

如回答不详细可追问

D. java怎么开通短信验证码登录功能

实现jiava短信验证码可以按下面的步奏进行:
1、首先,找到一个支持Java语言的接口短信平台。
2、接着下载接口文档,和自己的开发平台进行对接。
3、注意在对接之前测试一下短信的速度,一旦对接好想换就比较麻烦,之前就吃过这个亏,最后有个朋友介绍我去短信网。
4、如果要购买的话,一定要多测试几家。
如果在碰到有疑问的地方一定要和技术或者客服多多沟通。

E. 常用验证码之滑动验证码|图形验证码

这里是常用验证码的第三篇—— 滑动/图形验证码
在前两篇已经实现了随机验证码和算术验证码,感兴趣的可以去看一下~

除了这两种常用的验证码之外,现在最经常用到的还有几种,比如滑动验证,图片验证等,这一类的验证码一般借助于第三方来处理即可。比如图形验证码:

本篇纪录两种常用验证码的第三方调用方式:

人机验证服务适用于登录、注册、活动、论坛、短信等高风险业务场景。

通过对用户的行为数据、设备特征与网络数据构建多维度数据分析,使用业界先进的风控引擎结合“规则+AI”模型,对风险设备使用、模拟行为、暴力重放等攻击进行综合实时风控判决。

为网页、App、小程序开发者打造立体、全面的人机验证,最大程度地保护注册登录、活动秒杀、点赞发帖、数据保护等各大场景下的业务安全。

F. JAVAWEB项目怎么实现验证码

1、定义一个img指向后台服务
<img title="点击刷新" src="${pageContext.request.contextPath}/aa/img" class="img_login_code"
onclick="this.src='${pageContext.request.contextPath}/aa/img?'+Math.random();" />
2、服务
@RequestMapping(value="/img")
public void admin(HttpServletRequest request,HttpServletResponse response) throws Exception {
.outputImage("captcha_admin",null,null, request, response,verifyCode);
}
3、帮助类
package team.tool;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LinearGradientPaint;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class VerifyCodeUtils{

//使用到Algerian字体,系统里没有的话需要安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字符
public static final String VERIFY_CODES = "";
private static Random random = new Random();

/**
* 使用系统默认字符源生成验证码
* @param verifySize 验证码长度
* @return
*/
public static String generateVerifyCode(int verifySize){
return generateVerifyCode(verifySize, VERIFY_CODES);
}
/**
* 使用指定源生成验证码
* @param verifySize 验证码长度
* @param sources 验证码字符源
* @return
*/
public static String generateVerifyCode(int verifySize, String sources){
if(sources == null || sources.length() == 0){
sources = VERIFY_CODES;
}
int codesLen = sources.length();
Random rand = new Random(System.currentTimeMillis());
StringBuilder verifyCode = new StringBuilder(verifySize);
for(int i = 0; i < verifySize; i++){
verifyCode.append(sources.charAt(rand.nextInt(codesLen-1)));
}
return verifyCode.toString();
}

/**
* 生成随机验证码文件,并返回验证码值
* @param w
* @param h
* @param outputFile
* @param verifySize
* @return
* @throws IOException
*/
public static String outputVerifyImage(int w, int h, File outputFile, int verifySize) throws IOException{
String verifyCode = generateVerifyCode(verifySize);
outputImage(w, h, outputFile, verifyCode);
return verifyCode;
}

/**
* 输出随机验证码图片流,并返回验证码值
* @param w
* @param h
* @param os
* @param verifySize
* @return
* @throws IOException
*/
public static String outputVerifyImage(int w, int h, OutputStream os, int verifySize) throws IOException{
String verifyCode = generateVerifyCode(verifySize);
outputImage(w, h, os, verifyCode);
return verifyCode;
}

/**
* 生成指定验证码图像文件
* @param w
* @param h
* @param outputFile
* @param code
* @throws IOException
*/
public static void outputImage(int w, int h, File outputFile, String code) throws IOException{
if(outputFile == null){
return;
}
File dir = outputFile.getParentFile();
if(!dir.exists()){
dir.mkdirs();
}
try{
outputFile.createNewFile();
FileOutputStream fos = new FileOutputStream(outputFile);
outputImage(w, h, fos, code);
fos.close();
} catch(IOException e){
throw e;
}
}

/**
* 输出指定验证码图片流
* @param w
* @param h
* @param os
* @param code
* @throws IOException
*/
public static void outputImage(int w, int h, OutputStream os, String code) throws IOException{
int verifySize = code.length();
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Random rand = new Random();
Graphics2D g2 = image.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
Color[] colors = new Color[5];
Color[] colorSpaces = new Color[] { Color.WHITE, Color.CYAN,
Color.GRAY, Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE,
Color.PINK, Color.YELLOW };
float[] fractions = new float[colors.length];
for(int i = 0; i < colors.length; i++){
colors[i] = colorSpaces[rand.nextInt(colorSpaces.length)];
fractions[i] = rand.nextFloat();
}
Arrays.sort(fractions);

g2.setColor(Color.GRAY);// 设置边框色
g2.fillRect(0, 0, w, h);

Color c = getRandColor(200, 250);
g2.setColor(c);// 设置背景色
g2.fillRect(0, 2, w, h-4);

//绘制干扰线
Random random = new Random();
g2.setColor(getRandColor(160, 200));// 设置线条的颜色
for (int i = 0; i < 20; i++) {
int x = random.nextInt(w - 1);
int y = random.nextInt(h - 1);
int xl = random.nextInt(6) + 1;
int yl = random.nextInt(12) + 1;
g2.drawLine(x, y, x + xl + 40, y + yl + 20);
}

// 添加噪点
float yawpRate = 0.05f;// 噪声率
int area = (int) (yawpRate * w * h);
for (int i = 0; i < area; i++) {
int x = random.nextInt(w);
int y = random.nextInt(h);
int rgb = getRandomIntColor();
image.setRGB(x, y, rgb);
}

shear(g2, w, h, c);// 使图片扭曲

g2.setColor(getRandColor(100, 160));
int fontSize = h-4;
Font font = new Font("Algerian", Font.ITALIC, fontSize);
g2.setFont(font);
char[] chars = code.toCharArray();
for(int i = 0; i < verifySize; i++){
AffineTransform affine = new AffineTransform();
affine.setToRotation(Math.PI / 4 * rand.nextDouble() * (rand.nextBoolean() ? 1 : -1), (w / verifySize) * i + fontSize/2, h/2);
g2.setTransform(affine);
g2.drawChars(chars, i, 1, ((w-10) / verifySize) * i + 5, h/2 + fontSize/2 - 10);
}

g2.dispose();
ImageIO.write(image, "jpg", os);
}

/**
* 输出指定验证码图片流
* @param w
* @param h
* @param os
* @param code
* @throws IOException
*/
public static void outputImage(String key ,Integer w, Integer h, HttpServletRequest request, HttpServletResponse response, String code) throws IOException{
int verifySize = code.length();
w = w==null?80:w;
h = h==null?30:h;
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
request.getSession().setAttribute(key, code);
Random rand = new Random();
Graphics2D g2 = image.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
Color[] colors = new Color[5];
Color[] colorSpaces = new Color[] { Color.WHITE, Color.CYAN,
Color.GRAY, Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE,
Color.PINK, Color.YELLOW };
float[] fractions = new float[colors.length];
for(int i = 0; i < colors.length; i++){
colors[i] = colorSpaces[rand.nextInt(colorSpaces.length)];
fractions[i] = rand.nextFloat();
}
Arrays.sort(fractions);

g2.setColor(Color.GRAY);// 设置边框色
g2.fillRect(0, 0, w, h);

Color c = getRandColor(200, 250);
g2.setColor(c);// 设置背景色
g2.fillRect(0, 2, w, h-4);

//绘制干扰线
Random random = new Random();
g2.setColor(getRandColor(160, 200));// 设置线条的颜色
for (int i = 0; i < 20; i++) {
int x = random.nextInt(w - 1);
int y = random.nextInt(h - 1);
int xl = random.nextInt(6) + 1;
int yl = random.nextInt(12) + 1;
g2.drawLine(x, y, x + xl + 40, y + yl + 20);
}

// 添加噪点
float yawpRate = 0.05f;// 噪声率
int area = (int) (yawpRate * w * h);
for (int i = 0; i < area; i++) {
int x = random.nextInt(w);
int y = random.nextInt(h);
int rgb = getRandomIntColor();
image.setRGB(x, y, rgb);
}

shear(g2, w, h, c);// 使图片扭曲

g2.setColor(getRandColor(100, 160));
int fontSize = h-4;
Font font = new Font("Algerian", Font.ITALIC, fontSize);
g2.setFont(font);
char[] chars = code.toCharArray();
for(int i = 0; i < verifySize; i++){
AffineTransform affine = new AffineTransform();
affine.setToRotation(Math.PI / 4 * rand.nextDouble() * (rand.nextBoolean() ? 1 : -1), (w / verifySize) * i + fontSize/2, h/2);
g2.setTransform(affine);
g2.drawChars(chars, i, 1, ((w-10) / verifySize) * i + 5, h/2 + fontSize/2 - 10);
}

g2.dispose();
// 转成JPEG格式
ServletOutputStream out = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
}

private static Color getRandColor(int fc, int bc) {
if (fc > 255)
fc = 255;
if (bc > 255)
bc = 255;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r, g, b);
}

private static int getRandomIntColor() {
int[] rgb = getRandomRgb();
int color = 0;
for (int c : rgb) {
color = color << 8;
color = color | c;
}
return color;
}

private static int[] getRandomRgb() {
int[] rgb = new int[3];
for (int i = 0; i < 3; i++) {
rgb[i] = random.nextInt(255);
}
return rgb;
}

private static void shear(Graphics g, int w1, int h1, Color color) {
shearX(g, w1, h1, color);
shearY(g, w1, h1, color);
}

private static void shearX(Graphics g, int w1, int h1, Color color) {

int period = random.nextInt(2);

boolean borderGap = true;
int frames = 1;
int phase = random.nextInt(2);

for (int i = 0; i < h1; i++) {
double d = (double) (period >> 1)
* Math.sin((double) i / (double) period
+ (6.2831853071795862D * (double) phase)
/ (double) frames);
g.Area(0, i, w1, 1, (int) d, 0);
if (borderGap) {
g.setColor(color);
g.drawLine((int) d, i, 0, i);
g.drawLine((int) d + w1, i, w1, i);
}
}

}

private static void shearY(Graphics g, int w1, int h1, Color color) {

int period = random.nextInt(40) + 10; // 50;

boolean borderGap = true;
int frames = 20;
int phase = 7;
for (int i = 0; i < w1; i++) {
double d = (double) (period >> 1)
* Math.sin((double) i / (double) period
+ (6.2831853071795862D * (double) phase)
/ (double) frames);
g.Area(i, 0, 1, h1, 0, (int) d);
if (borderGap) {
g.setColor(color);
g.drawLine(i, (int) d, i, 0);
g.drawLine(i, (int) d + h1, i, h1);
}

}

}
public static void main(String[] args) throws IOException{
File dir = new File("F:/verifies");
int w = 200, h = 80;
for(int i = 0; i < 50; i++){
String verifyCode = generateVerifyCode(4);
File file = new File(dir, verifyCode + ".jpg");
outputImage(w, h, file, verifyCode);
}
}
}

阅读全文

与滑动验证码java相关的资料

热点内容
日本大胸电影 浏览:568
黄色的电视剧的app有哪些 浏览:520
word视图没有工具栏 浏览:108
模拟城市5启动程序 浏览:21
法国啄木鸟电影网站 浏览:361
蓝光电影在线免费观看 浏览:123
国内免费网址看电影 浏览:240
VC指的是哪个编程软件 浏览:815
加工编程培训班需要什么手续 浏览:869
win10没有自带的看图软件 浏览:438
香港3级鬼片 浏览:329
疫情数据怎么没有美国 浏览:720
苹果电影高清版下载地址 浏览:165
有一部电影女主角头发是绿金发的叫什么名 浏览:197
古代一女多男肉文 浏览:338
老武打片100部正片 浏览:450
换眼睛伦理电影 浏览:970
日本鸭子的电影 浏览:456
小说主角叫齐天的是什么小说 浏览:912
免费飞卢小说破解网站 浏览:820

友情链接