网上的前端验来源gaodai#ma#com搞@@代~&码网证码逻辑总感觉不安全,验证码建议还是使用后端配合验证。本文主要介绍了asp.net core配合vue实现后端验证码逻辑,感兴趣的可以了解一下
概述
网上的前端验证码逻辑总感觉不安全,验证码建议还是使用后端配合验证。
如果产品确定可以上网的话,就可以使用腾讯,百度等第三方验证,对接方便。但是产品可能内网部署,就必须自己写了。
本文章就是基于这一点来实现的。
前端验证码显示一个图片,后端生成图片。
部分原理
1.前端调用生端获取图片时,传入一个roomID,后端生成一个4位验征码,放入redis中。然后生成一个图片返回。
2.前端显示图片,登录时将roomID和填写的验证码,一并提交,登录接口根据roomId从redis中取出验证码判断是否正确。
这样就相当于后端验证了。
大家觉得有问题什么,可以进行评论。谢谢。
源码
前端部分代码
智能综合管理系统
登录
import { validUsername } from '@/utils/validate' import Identify from './components/Identify' import { uuid } from 'vue-uuid'; // uuid object is also exported to things // outside Vue instance. export default { name: 'Login', components: { Identify }, data() { const validateUsername = (rule, value, callback) => { if (!validUsername(value)) { callback(new Error('请输入正确的用户名')) } else { callback() } } const validatePassword = (rule, value, callback) => { if (value.length = 'A' && key { this.$refs.password.focus() }) }, createUuid() { let uuidV4 = uuid.v4().replace('-', '').replace('-', '').replace('-', '').replace('-', '') this.verifyImageRoomId = uuidV4 this.verifyImageUrl = '/api/Operator/getCaptchaImage/120/40/' + this.verifyImageRoomId console.log(uuidV4) }, handleLogin() { this.$refs.loginForm.validate(valid => { if (valid) { this.loading = true this.$store.dispatch('user/login', this.loginForm) .then(() => { this.$router.push({ path: this.redirect || '/', query: th
以上就是asp.net core配合vue实现后端验证码逻辑的详细内容,更多请关注gaodaima搞代码网其它相关文章!