首页 > 其他分享 >验证码,发送短信验证码,校验确认密码和密码,密码需要数字字母特殊字符任选2种组合

验证码,发送短信验证码,校验确认密码和密码,密码需要数字字母特殊字符任选2种组合

时间:2023-05-04 16:47:17浏览次数:45  
标签:callback color 验证码 height 密码 position 校验 font

密码需要数字字母特殊字符任选2种组合

const validatePwd=(rule, value, callback)=>{
      const reg=/(?!^(\d+|[a-zA-Z]+|[~!@#$%^&*?]+)$)^[\w~!@#$%^&*?]{8,32}$/
      if (reg.test(value) == true ) {
        callback()
      } else {
        callback(new Error('密码格式错误'))
      }
    }
 rules: {
        password: [{ required: true, message: '密码长度8-32位,请使用数字、字母、特殊字符的至少两种进行组合', trigger: 'blur',validator:validatePwd }],

      },

验证码,发送短信验证码,校验确认密码和密码(图片和相关接口不在,会报错,自取验证部分)

<template>
  <div>
    <div>

    </div>
    <div class="login-container">
      <img class="login-bg" src="@/assets/login_images/loginBg.png" alt="loginBG"/>
      <img class="login-logo" src="../../assets/login_images/BS_logo.png" alt="logo"/>

      <img
        class="login-bitmap"
        src="../../assets/login_images/bitmap.png"
        alt="bitmap"
      />

      <div class="login-container-left">
        <img
          class="login-cardBg"
          src="../../assets/login_images/login-cardBg.png"
          alt="loginCardBg"
        />
      </div>
      <div class="login-container-right">
        <el-form
          :rules="rules" :model="ruleForm"
          ref="ruleForm"
          class="login-form"
          autocomplete="on"
          label-position="left"
        >
          <div class="title-container" v-if="pedMethod === 'code'">
            <div class="title1">忘记密码</div>
            <div class="title2">请通过手机短信验证码进行密码重置</div>
          </div>
          <div v-if="pedMethod === 'code'">
            <el-form-item prop="username">

              <el-input
                ref="phone"
                v-model="phone"
                placeholder="请输入手机号"
                name="phone"
                type="text"
                maxlength="11"
                autocomplete="on"
              />
              <span class="input-btns">
                <span
                  v-if="phone"
                  class="show-close"
                  @click="clearPhone"
                >
                  <i class="el-icon-circle-close"></i>
                </span>
              </span>
            </el-form-item>

            <el-form-item prop="SMSCaptcha    ">
              <el-input
                v-model="SMSCaptcha"
                type="text"
                placeholder="请输入验证码"
                name="SMSCaptcha    "
                autocomplete="on"
                clearable
                maxlength="6"
              />
              <div class="getCode" v-if="!isSend" @click="sendSms">获取验证码</div>
              <div class="getCode" v-if="isSend">{{ time }}</div>
            </el-form-item>
            <el-button
              :loading="loading"
              type="primary"
              style="
                width: 100%;
                margin-bottom: 12.5%;
                margin-top: 8.15%;
                background: #165dff;
              "
              @click="nextProgess"
            >
              下一步
            </el-button>
          </div>
          <div class="title-container" v-if="pedMethod === 'reset'">
            <div class="title3" @click="toPre"> <返回上一步 </div>
            <div class="title1">设置密码</div>
            <div class="title2">当前账号{{ phone }}</div>
          </div>
          <div v-if="pedMethod === 'reset'">
            <el-form-item prop="password">
              <el-input
                ref="password"
                v-model="ruleForm.password"
                placeholder="请设置密码"
                name="password"
                type="text"
                autocomplete="on"
                clearable
              />
            </el-form-item>

            <el-form-item prop="password1">
              <el-input
                ref="password1"
                v-model="ruleForm.password1"
                placeholder="确认密码"
                name="password1"
                type="text"
                autocomplete="on"
                clearable
              />
            </el-form-item>
            <el-button
              :loading="loading"
              type="primary"
              style="
                width: 100%;
                margin-bottom: 12.5%;
                margin-top: 8.15%;
                background: #165dff;
              "
              @click="onSubmit('ruleForm')"
            >
              确定
            </el-button>
          </div>

        </el-form>
      </div>
    </div>

  </div>
</template>

<script>
import { sendSms, resetPasswordBySms } from '@/api/setting/resetPwd'
import md5 from 'md5'

export default {
  name: 'Login',
  data() {
    const validatePsd1 = (rule, value, callback) => {
      if (value == '') {
        callback(new Error('请输入确认密码'))
      } else if (this.ruleForm.password == '') {
        callback(new Error('请先输入密码'))
        this.ruleForm.password1 = ''
      } else if (value != this.ruleForm.password) {
        callback(new Error('确认密码与密码不一致'))
      } else {
        callback()
      }
    }
    const validatePsd = (rule, value, callback) => {
      const reg=/(?!^(\d+|[a-zA-Z]+|[~!@#$%^&*?]+)$)^[\w~!@#$%^&*?]{8,20}$/
      if (reg.test(value) == true ) {
        if (value == '') {
          callback(new Error('请输入密码'))
        } else if (this.ruleForm.password == '') {
          callback(new Error('请输入密码'))
        } else if (value.length < 8 || value.length > 32) {
          callback(new Error('密码不少于8位,不大于32位'))
        } else {
          callback()
        }
      } else {
        callback(new Error('密码长度8-32位,请使用数字、字母、特殊字符的至少两种进行组合'))
      }

    }

    return {
      loading: false,
      ruleForm: {
        password: '',
        password1: ''
      },
      rules: {
        password: [{ required: true, validator: validatePsd, trigger: 'blur' }],
        password1: [{ required: true, validator: validatePsd1, trigger: 'blur' }]
      },
      pedMethod: 'code',
      isSend: false,
      time: 180,
      phone: '',
      SMSCaptcha: ''
    }
  },
  watch: {},
  methods: {

    clearPhone() {
      this.phone = ''
    },
    clearUsername() {
      this.loginForm.username = ''
    },
    toPre(){
      this.pedMethod = 'code'
    },
    nextProgess() {
      if (!this.phone) {
        this.$message({
          message: '请输入手机号',
          type: 'warning'
        })
        return
      }
      if (!this.checkMobile(this.phone)) {
        this.$message({
          message: '手机号输入错误',
          type: 'warning'
        })
        return
      }
      if (!this.SMSCaptcha) {
        this.$message({
          message: '请输入验证码',
          type: 'warning'
        })
        return
      }
      this.pedMethod = 'reset'
    },
    checkMobile(mobile = '') {
      return /^1[3-9][0-9]{9}$/.test(mobile)
    },
    sendSms() {
      let _this = this
      try {

        if (!this.phone) {
          _this.$message({
            message: '请输入手机号',
            type: 'warning'
          })
          return
        }

        if (!this.checkMobile(this.phone)) {
          _this.$message({
            message: '手机号输入错误',
            type: 'warning'
          })
          return
        }
        sendSms({
          SMStype: 283,
          terminalType: 4,
          phone: this.phone
        })
          .then(res => {
            if (res.code == 200) {
              _this.countdown(_this)
            }
          })
          .catch(err => {

          })

      } catch (err) {

      }
    },
    countdown(that) {
      var second = that.time
      if (second == 0) {
        that.isSend = false,
        that.time = 180
        return
      }
      that.isSend = true
      var time = setTimeout(function() {
        that.time = second - 1
        that.countdown(that)
      }, 1000)
    },
    savePasswordBySms() {
      this.loading = true
      resetPasswordBySms({
        SMStype: 283,
        terminalType: 4,
        phone: this.phone,
        SMSCaptcha: this.SMSCaptcha,
        newPassword: this.ruleForm.password,
        confirmPassword: this.ruleForm.password1
      })
        .then(res => {
          if (res.code == 200) {
            _this.countdown(_this)
          }
          this.loading = false
        })
        .catch(err => {
          this.loading = false
        })
    },
    onSubmit(formName) {
      let _this = this
      this.$refs[formName].validate(valid => {
        if (this.ruleForm.password1 == this.ruleForm.password) {
          if (valid) {
            _this.savePasswordBySms()
          }
        } else {
          console.log(this.ruleForm.password)
          console.log(this.ruleForm.password1)
          this.$message({
            message: '密码与确认密码不一致!',
            type: 'warning'
          })
        }
      })
    }

  },
  created() {

  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
$bg: #f4f6f8;
$light_gray: #070707;
$loginCursorColor: #1F2329;
$lightGray: #1F2329;
$darkGray: #E7F0FE;
$loginBg: #2d3a4b;

.login-container {
  .el-input {
    display: inline-block;
    height: 40px;
    width: 100%;

    input {
      height: 40px;
      // background: transparent;
      background-color: #F0F5FE;
      opacity: 1;
      border: 0px;
      border-radius: 0px;
      padding-right: 78px;
      color: $lightGray;
      caret-color: $loginCursorColor;
      -webkit-appearance: none;
      font-size: 14px;

      &:-webkit-autofill {
        // box-shadow: 0 0 0px 1000px $loginBg inset !important;
        // -webkit-text-fill-color: #fff !important;
      }

      &:focus {
        border: 1px solid #165dff;
      }
    }
  }

  :v-deep.el-form-item {
    border: 1px solid #dee0e3;
    // background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #1f2329;
  }

  ::v-deep.el-form-item__error {
    position: absolute !important;
  }
}

/* reset element-ui css */
.login-container {
  ::v-deep.el-input {
    display: inline-block;
    height: 47px;
    width: 76%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 0;
      color: $light_gray;
      height: 47px;

      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: #070707 !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid #f4f6f8;
    background: #f4f6f8;
    border-radius: 5px;
    color: #070707;
  }
}

.login-container {
  position: absolute;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-color: $loginBg;
  background: linear-gradient(360deg, #f3f8ff 0%, #eaf3ff 100%);

  .login-container-left {
    z-index: 2;
    width: 37%;
    height: 58.06%;
    position: absolute;
    top: 22.41%;
    bottom: 19.54%;
    left: 12.19%;
    // overflow: hidden;
    .login-cardBg {
      width: 100%;
      height: auto;
    }
  }

  .login-container-right {
    z-index: 2;
    position: absolute;
    top: 22.59%;
    height: auto;
    // min-height: 54.81%;
    // max-height: 100%;
    // bottom: 22.59%;
    left: 52.6%;
    width: 27.08%;
    background: linear-gradient(
        221deg,
        rgba(251, 252, 253, 0.4) 0%,
        rgba(255, 255, 255, 0.7) 100%
    );
    box-shadow: 5px 6px 23px 0px rgba(133, 168, 211, 0.16);
    border-radius: 12px;
    border: 2px solid #ffffff;

    .login-form {
      position: relative;
      width: 100%;
      max-width: 100%;
      padding: 11.49% 11.92% 0;
      margin: 0 auto;
      overflow: hidden;
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    // color: $darkGray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 24px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 600;
      color: #1f2329;
      line-height: 36px;
    }

    .title1 {
      font-size: 20px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 600;
      color: #1f2329;
      line-height: 30px;
      margin: 0 0 0 0;
    }

    .title2 {
      font-size: 12px;
      font-family: PingFangSC-Medium, PingFang SC;
      color: #1f2329;
      line-height: 30px;
      margin: 0 0 8.44% 0;
    }
  }

  .input-btns {
    position: absolute;
    right: 10px;
    top: 0;
    z-index: 3;
  }

  .show-pwd {
    // position: absolute;
    // right: 40px;
    // top: 0;
    margin-right: 8px;
    font-size: 16px;
    color: #bbbfc4;
    cursor: pointer;
    user-select: none;
  }

  .show-close {
    // position: absolute;
    // right: 10px;
    // top: 0;
    font-size: 16px;
    color: #bbbfc4;
    cursor: pointer;
    user-select: none;
  }
}

.login-bg {
  display: block;
  position: fixed;
  width: 101%;
  height: 101%;
  // background: #0e1d30;
  background: #F3F6F9;
  left: -5px;
  top: -5px;
  z-index: 1;
}

.login-logo {
  width: 24%;
  position: absolute;
  left: 0px;
  top: 0;
  z-index: 2;
}

.login-bitmap {
  width: 20.57%;
  position: absolute;
  right: 129px;
  top: 66px;
  z-index: 2;
}

.el-form-item__content {
  line-height: 40px;
  position: relative;
  font-size: 14px;
  padding: 0 15px;
}

.login-container .el-input {
  padding: 0 15px !important;
  width: 100% !important;
}

.getCode {
  position: absolute;
  right: 10px;
  top: 0;
  z-index: 3;
  cursor: pointer;
  color: #165DFF;
  font-family: PingFangSC-Medium, PingFang SC;
}
.title3{
  font-size: 14px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 600;
  color: #165DFF;
  line-height: 30px;
  margin: 0 0 4% 0;
  cursor: pointer;

}
</style>

 

标签:callback,color,验证码,height,密码,position,校验,font
From: https://www.cnblogs.com/shuihanxiao/p/17371701.html

相关文章

  • jenkins 查看凭证密码以及重置admin密码的操作方法
    找回凭证密码打开Jenkins的系统管理页面的脚本命令行页面  在输入框输入如下代码点击运行即可查看所有凭证对应的密码:  按下ctrl+F组合键查找凭证ID就能搜索到该凭证对应的密码对单个凭据解密jenkins下找到credentials.xml 文件中<password>中对应的字符串......
  • django-channel 配置 channel layer 添加redis的账号和密码
    最近公司要使用django-channel搭建socket, 文档:https://channels.readthedocs.io/en/stable/introduction.html文档里面并没有写如果redis有账号和密码的话,怎么配置。配置方法:https://github.com/django/channels/issues/164#issuecomment-220513297如下:CHANNEL_LAYERS......
  • 若依登录验证码不显示404访问问题
    最近在学习接触Java,那若依开源项目来练练手,部署后发现登录界面的登录验证码一直刷不出来,提示404访问错误。查看网上一直没找到解决办法。但知道原理都是配置文件的问题。后来在一个其他项目上找到灵感,给nginx的nginx.conf配置文件增加配置信息,项目可以正常启动并可以正常登录了。......
  • SAP ERP系统MM模块常用增强之四:采购申请输入字段的校验检查
    在SAP/ERP项目的实施中采购管理模块(MM)的创建和修改采购申请一般都会有输入字段校验检查的需求,来防止业务人员录入错误或少录入数据,这方面需求部分是可以通过配置实现,比如一些字段是否必输,是否显示等,但是在实际项目中还是会遇到一些特殊的需求,比如需要一定逻辑判断的需求就不能通过......
  • 直播app开发搭建,图形和短信验证码的自动识别获取
    直播app开发搭建,图形和短信验证码的自动识别获取selenuim操作 driver=webdriver.Chrome()driver.get("https://locvps.wenjingnetwork.com/page.aspx?c=reg")driver.implicitly_wait(10)#设置超时时间driver.find_element_by_name("uname").send_keys()driver.find_element_by......
  • oracle修改用户密码的方法
    Oracle用户名及默认密码 修改oracle用户的密码有以下方法:普通用户 (1)通过alteruser语法来进行修改,这也是最常见的方式:(2)第二种方式,是通过password命令来修改:从安全性角度来说,推荐大家通过第二种方式来修改用户密码,这样可防止明文密码泄露。sys用户......
  • 解决上传md文件时出现的“<Fault 401: '请配置正确的用户名与访问令牌(access token),
    使用的工具:pycnbolg下载地址:https://github.com/dongfanger/pycnblog具体操作按这位大神的博客:如何在博客园上传markdown文件-NotYourferry-博客园(cnblogs.com)出现报错如图:偶然看到这两位的评论:于是我将config.yaml中的password改成了我的令牌,就上传成功了。......
  • SpringMVC03_校验和拦截器
    以下代码全过程在上篇一、SpringMVC校验​ 举一个简单的例子,在登陆时我们要检验用户名是否输入、密码是否合法。(一)引入依赖框架​ 在Spring-MVC中我们需要添加Hibernate的Validator检验框架,注意下面的版本号,615Final对应的应该是importjavax.validation.constraints......
  • m基于整数序列的QC-LDPC的稀疏校验矩阵构造算法性能对比matlab仿真,对比差分序列,PEG,
    1.算法仿真效果matlab2013b仿真结果如下:  2.算法涉及理论知识概要       QC-LDPC(Quasi-CyslicLow-DensityParity-CheckCodes)即准循环LDPC码。之前介绍的LDPC码基本属于随机构造法,构造出的码性能很好,但校验矩阵具有不规律性,存在校验矩阵存储于读取困难、编码复......
  • m基于大衍数无高阶环稀疏校验矩阵H构造算法和RMP消息传递的QC-LDPC性能matlab仿真
    1.算法仿真效果matlab2017b仿真结果如下:   2.算法涉及理论知识概要LDPC码早于1962年由Gallager提出,可以看成是一个具有稀疏校验矩阵的线性分组码。自从Mackay和Neal发现LDPC码的性能非常接近香农限以后,LDPC码越来越受到人们的重视。基于准循环LDPC(QC-LDPC)码结......