短信验证框

验证框

业务需求如下,这是个企业激活码和短信验证码类似
在这里插入图片描述
使用技术栈vue3 + element plus

HTML 代码如下
  <div>
   <div class="key-text">企业激活码</div>
    <div class="login-box-key" @click="clickInputBox">
      <div v-for="(item, index) in 6">
        <div>{{ inputValue[index] }}</div>
      </div>
    </div>
    <el-input ref="ipt" class="input-code" v-model.trim="inputValue" maxlength="6"/>
  </div>
Js 代码
import { defineComponent, ref, nextTick } from 'vue'

export default defineComponent({
	setup() {
		let inputValue = ref('')
		const ipt = ref(null)
		// 点击div 聚焦
		const clickInputBox = () => {
			nextTick(() => {
				ipt.value.focus()
			})
		}
	}
})

CSS input 样式

      .input-code {
        position: absolute;
        left: -9999px;
        top: -99999px;
        width: 0;
        height: 0;
        opacity: 0;
        overflow: visible;
        z-index: -1;
      }

结果
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
手机短信验证是一种常用的用户身份验证方式。实现手机短信验证需要以下步骤: 1. 用户输入手机号码,点击发送验证码按钮。 2. 后端接收到请求后,生成一个随机的验证码,并将其保存到缓存中(如Redis),同时将验证码发送给用户的手机。 3. 用户输入收到的验证码,点击验证按钮。 4. 后端接收到请求后,从缓存中获取对应手机号码的验证码,与用户输入的验证码进行比对,如果一致则认为验证通过,否则认为验证失败。 下面是一个简单的实现示例(使用Flask架和Redis数据库): ```python from flask import Flask, request import redis import random app = Flask(__name__) r = redis.Redis(host='localhost', port=6379, db=0) # 生成随机验证码 def generate_verification_code(): return '%06d' % random.randint(0, 999999) # 发送验证码 @app.route('/send_verification_code', methods=['POST']) def send_verification_code(): phone_number = request.form['phone_number'] verification_code = generate_verification_code() r.set(phone_number, verification_code, ex=300) # 将验证码保存到Redis,并设置5分钟过期时间 # TODO: 调用短信服务商API发送验证码到用户手机 return 'Verification code {} has been sent to {}'.format(verification_code, phone_number) # 验证验证码 @app.route('/verify_verification_code', methods=['POST']) def verify_verification_code(): phone_number = request.form['phone_number'] user_verification_code = request.form['verification_code'] verification_code = r.get(phone_number) if verification_code is None: return 'Verification code has expired or does not exist' elif verification_code.decode('utf-8') != user_verification_code: return 'Verification code is incorrect' else: r.delete(phone_number) # 验证通过后删除Redis中的验证码 return 'Verification succeeded' if __name__ == '__main__': app.run() ``` 在实际应用中,还需要考虑以下问题: 1. 如何防止恶意攻击:可以设置每个手机号码一天内只能发送一定数量的验证码,或者使用图形验证码等方式。 2. 如何保护用户隐私:应该使用 HTTPS 加密传输用户手机号码和验证码,同时不应将验证码存储在日志等明文存储的地方。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值