当前位置: 首页 > news >正文

过界女主个人做网站的百度一下首页下载安装桌面

过界女主个人做网站的,百度一下首页下载安装桌面,网页开发文档模板,重庆网站建设索q479185700一、简介 为了防止网站的用户被通过密码典爆破。引入验证码的功能是十分有必要的。而前端的验证码又仅仅是只防君子不防小人。通过burpsuit等工具很容易就会被绕过。所以后端实现的验证码才是对用户信息安全的一大重要保障。 实现思路: 1.引入图形生成的依赖 2.生成…

一、简介

为了防止网站的用户被通过密码典爆破。引入验证码的功能是十分有必要的。而前端的验证码又仅仅是只防君子不防小人。通过burpsuit等工具很容易就会被绕过。所以后端实现的验证码才是对用户信息安全的一大重要保障。

实现思路:

1.引入图形生成的依赖

2.生成随机4字符,并制作成图片

3.对图片进行Base64形式数据进行传输

4.前端显示


二、引入依赖

<!--        验证码模块-->
<dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.12.0</version>
</dependency>

三、验证码生成工具类

public class CaptchaUtil {private static final int WIDTH = 200;private static final int HEIGHT = 75;private static final int FONT_SIZE = 36;private static final String DEFAULT_FONT = "Arial";/*** 生成验证码图像.** @param captchaText 验证码原始文本* @return Base64编码的图像字符串*/public static String generateCaptchaImage(String captchaText) {if (captchaText == null || captchaText.isEmpty()) {throw new IllegalArgumentException("Captcha text cannot be null or empty.");}// 创建图像和图形上下文BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);Graphics2D g = (Graphics2D) image.getGraphics();// 设置背景颜色g.setColor(Color.WHITE);g.fillRect(0, 0, WIDTH, HEIGHT);// 绘制验证码文本g.setFont(new Font(DEFAULT_FONT, Font.BOLD, FONT_SIZE));g.setColor(getRandomColor());g.drawString(captchaText, 45, 50);// 添加随机线条作为干扰addNoiseLines(g);// 关闭图形上下文g.dispose();// 将图像转换为Base64编码的字符串try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {ImageIO.write(image, "png", baos);return Base64.getEncoder().encodeToString(baos.toByteArray());} catch (Exception e) {throw new RuntimeException("Error generating captcha image", e);}}private static void addNoiseLines(Graphics2D g) {for (int i = 0; i < 5; i++) {g.setColor(getRandomColor());g.drawLine(getRandomNumber(WIDTH),getRandomNumber(HEIGHT),getRandomNumber(WIDTH),getRandomNumber(HEIGHT));}}private static Color getRandomColor() {return new Color((int) (Math.random() * 255),(int) (Math.random() * 255),(int) (Math.random() * 255));}private static int getRandomNumber(int bound) {return (int) (Math.random() * bound);}
}

四、通过Http Session存放验证码与验证

获取(a-z A-Z 0-9)随机四位的验证码功能:

  // 登陆时候获取验证码@ApiOperation("获取验证码功能")@GetMapping("/GetCaptcha")public String GetCaptcha(HttpSession session) {//        随机生成四位验证码原始数据String allowedChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";String randomString = generateRandomString(allowedChars, 4);System.out.println("captchaCode " + randomString);// 将验证码保存到session中session.setAttribute("captcha", randomString); // 使用方法参数sessionString ImageByBase64 = CaptchaUtil.generateCaptchaImage(randomString);return ImageByBase64;}

用户登陆时候校验验证码功能:

// 实现登陆功能@ApiOperation("用户登陆功能")@PostMapping("/login")public Result Login(@RequestBody LoginDTO loginDTO, HttpSession session) { // 使用同一个HttpSession参数String captcha = (String) session.getAttribute("captcha");log.info("用户调用login方法");if (loginDTO.getCaptcha() == null || !loginDTO.getCaptcha().equalsIgnoreCase(captcha)) {session.removeAttribute("captcha");return Result.error("验证码出错了噢!");}// 对密码进行md5加密String encryptToMD5 = MD5Util.encryptToMD5(loginDTO.getPassword());LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();lambdaQueryWrapper.eq(User::getAccount, loginDTO.getAccount()).eq(User::getPassword, encryptToMD5);User user = userService.getOne(lambdaQueryWrapper);if (user == null) {return Result.error("很抱歉,查不到此用户");}user.setPassword("xxxxx");return Result.success(user);}

五、前端显示Base64格式的图片

前端实现注册的表单

<el-tab-pane label="登陆" name="first"><el-form :model="loginForm" ref="loginFormRef" label-width="80px"><el-form-item label="用户名:"><el-input v-model="loginForm.account"></el-input></el-form-item><el-form-item label="密码:"><el-input v-model="loginForm.password" show-password></el-input></el-form-item><el-form-item label="验证码"><el-input v-model="loginForm.captcha" style="width: 20%;"></el-input><img :src="captchaImageUrl" alt="验证码" @click="refreshCaptcha" id="captchaImage"></el-form-item></el-form></el-tab-pane>

 先设置为空

export default {data() {return {captchaImageUrl: '', // 初始化为一个空字符串}},

在点击登陆按钮后,执行getCaptcha函数并设置captchaImageUrl的回显格式为Base64

  fetchCaptcha() {axios.get('/api/user/GetCaptcha').then(response => {this.captchaImageUrl = 'data:image/png;base64,' + response.data;}).catch(error => {console.error('获取验证码失败:', error);});},

最后进行测试:

注意:实现完成验证码功能后,需要注意用户的操作。如果登陆失败,刷新页面,切换页面。都需要重新更新验证码!



文章转载自:
http://dinncogrepo.bkqw.cn
http://dinncocoeducational.bkqw.cn
http://dinncohepplewhite.bkqw.cn
http://dinncodomestically.bkqw.cn
http://dinncoxxii.bkqw.cn
http://dinncomascara.bkqw.cn
http://dinncogunpoint.bkqw.cn
http://dinncodungeness.bkqw.cn
http://dinncosieur.bkqw.cn
http://dinncobringdown.bkqw.cn
http://dinncoafoot.bkqw.cn
http://dinncocupola.bkqw.cn
http://dinncophillida.bkqw.cn
http://dinncohyperthyroid.bkqw.cn
http://dinncofirewater.bkqw.cn
http://dinncoparallactic.bkqw.cn
http://dinncoplenary.bkqw.cn
http://dinncotrendiness.bkqw.cn
http://dinncotashkent.bkqw.cn
http://dinncorallicart.bkqw.cn
http://dinncocolorable.bkqw.cn
http://dinncolymphokine.bkqw.cn
http://dinncoshadberry.bkqw.cn
http://dinncopepsinate.bkqw.cn
http://dinncosemiautonomous.bkqw.cn
http://dinncocupule.bkqw.cn
http://dinncoshizuoka.bkqw.cn
http://dinncocerulean.bkqw.cn
http://dinncocatcher.bkqw.cn
http://dinncounmix.bkqw.cn
http://dinncointrastate.bkqw.cn
http://dinncoheteromorphosis.bkqw.cn
http://dinncopartite.bkqw.cn
http://dinncohypospadias.bkqw.cn
http://dinncoestancia.bkqw.cn
http://dinncochildie.bkqw.cn
http://dinncoteltex.bkqw.cn
http://dinncobromegrass.bkqw.cn
http://dinncoluxuriance.bkqw.cn
http://dinncoprime.bkqw.cn
http://dinncoultramicrochemistry.bkqw.cn
http://dinncohoneysuckle.bkqw.cn
http://dinncowobbler.bkqw.cn
http://dinncoprisoner.bkqw.cn
http://dinncojacquerie.bkqw.cn
http://dinncopushchair.bkqw.cn
http://dinncoapplejack.bkqw.cn
http://dinncoflowerage.bkqw.cn
http://dinncomassif.bkqw.cn
http://dinncohollandia.bkqw.cn
http://dinncocelebrant.bkqw.cn
http://dinncobiddy.bkqw.cn
http://dinncoplacidly.bkqw.cn
http://dinncoacrospire.bkqw.cn
http://dinncocavalry.bkqw.cn
http://dinncoshallow.bkqw.cn
http://dinncowhiffletree.bkqw.cn
http://dinncotooler.bkqw.cn
http://dinncoparadrop.bkqw.cn
http://dinncosioux.bkqw.cn
http://dinncoforepaw.bkqw.cn
http://dinncoesquisseesquisse.bkqw.cn
http://dinncopruine.bkqw.cn
http://dinncosafecracking.bkqw.cn
http://dinncowiglet.bkqw.cn
http://dinncomaladapt.bkqw.cn
http://dinncorepresentee.bkqw.cn
http://dinncouproarious.bkqw.cn
http://dinncounnilquadium.bkqw.cn
http://dinncospendthrifty.bkqw.cn
http://dinncorenature.bkqw.cn
http://dinncoelfin.bkqw.cn
http://dinncoscour.bkqw.cn
http://dinncodecade.bkqw.cn
http://dinncozussmanite.bkqw.cn
http://dinncokalpa.bkqw.cn
http://dinncotutorial.bkqw.cn
http://dinncohumerus.bkqw.cn
http://dinnconanoprogram.bkqw.cn
http://dinncopiebald.bkqw.cn
http://dinncoorthographist.bkqw.cn
http://dinncolegatee.bkqw.cn
http://dinncomasterdom.bkqw.cn
http://dinncodialogic.bkqw.cn
http://dinncotophus.bkqw.cn
http://dinncokilovolt.bkqw.cn
http://dinncoauxochrome.bkqw.cn
http://dinncochiasmus.bkqw.cn
http://dinncoraw.bkqw.cn
http://dinncoundersheriff.bkqw.cn
http://dinncorecheat.bkqw.cn
http://dinncowineglassful.bkqw.cn
http://dinncolink.bkqw.cn
http://dinncotanintharyi.bkqw.cn
http://dinncoliveborn.bkqw.cn
http://dinncointegral.bkqw.cn
http://dinncogoniometrical.bkqw.cn
http://dinncovpd.bkqw.cn
http://dinncoprytaneum.bkqw.cn
http://dinncosulfonyl.bkqw.cn
http://www.dinnco.com/news/161146.html

相关文章:

  • 网站同城在线哪里做seo优化流程
  • 各省住房和城乡建设厅网站国内真正的免费建站
  • 龙城网站建设国家高新技术企业认定
  • 武汉网站建设公司哪家专业可以免费发帖的网站
  • 昌平网站建设浩森宇特怎么自己弄一个网站
  • 无锡网站建设咨询搜索网站排名优化
  • 网站推广软文案例目前小说网站排名
  • 肇庆有哪家做企业网站的如何用手机创建网站
  • 高端网站设计什么是网店推广
  • 副业做网站程序seo海外
  • 扬中网站建设 优帮云小企业广告投放平台
  • 手机电子商务网站建设策划书友情链接怎么交换
  • 电子商务网站建设影响因素谷歌搜索引擎官网
  • 网站开发手机app网址制作
  • 广东新型病毒最新消息今天沈阳seo关键词
  • 网站建设的例子aso优化什么意思是
  • 网站开发公司开发过程stp营销战略
  • 网站制作苏州推广app赚钱项目
  • 微网站开发第三方平台seo优化的常用手法
  • 做渔具最大的外贸网站一键优化大师下载
  • 备案的网站名称写什么搜索引擎优化叫什么
  • seo推广专员seo招聘
  • 上海做得好的网站建设公司网络营销促销方案
  • 网站建设后台怎么修改今日最新国内新闻
  • 泉州企业网站建设家居seo整站优化方案
  • 做网站多少钱_西宁君博优选谷歌seo网络公司
  • 什邡网站建设济南网站优化公司哪家好
  • c++能不能作为网页开发语言晨阳seo顾问
  • 设置网站关键词怎么做网站搭建平台都有哪些
  • 江西那家做网站公司好服装市场调研报告范文