zoukankan      html  css  js  c++  java
  • 防止注册机,登录时-验证码图片的生成=前端vue+后端node

    前端

     <section class="login-message">
                    <input type="text" maxlength="11" placeholder="验证码" v-model="captcha">
                    <img
                      ref="captcha"
                      class="get-verification"
                      src="http://localhost:3000/api/captcha"
                      alt="captcha"
                      @click.prevent="getCaptcha()"
                    >
                  </section>
    

      点击验证码图片事件

    // 4. 获取图形验证码
    getCaptcha() {
    // 加一个时间戳作用:让验证码时时刻刻不一样
    this.$refs.captcha.src = 'http://localhost:3000/api/captcha?time=' + new Date();
    }

    ------------------------------------------------------------------------------
    后端生成验证码接口
    router.get('/api/captcha', (req, res) => {
        // 1. 生成随机验证码
        let captcha = svgCaptcha.create({
            color: true,
            noise: 3, // 三条干扰线
            ignoreChars: '0o1i',
            size: 4
        });
        // console.log(captcha.text);
    
        // 2. 保存
        req.session.captcha = captcha.text.toLocaleLowerCase();
        console.log(req.session);
    
        // 3. 返回客户端
        res.type('svg');
        res.send(captcha.data);
    });
    

      



  • 相关阅读:
    NOI2010 能量采集
    NOI2011 兔兔与蛋蛋游戏
    动态规划——min/max的单调性优化总结
    NOI2011 NOI嘉年华
    NOI2011 阿狸的打字机
    NOI2011 智能车比赛
    NOI2011 兔农
    NOI2012 魔幻棋盘
    NOI2012 美食节
    NOI2012 迷失游乐园
  • 原文地址:https://www.cnblogs.com/fdxjava/p/12271348.html
Copyright © 2011-2022 走看看