编写后台登录滑动成功获取验证码 人机验证

vue-puzzle-vcode

Vue 纯前端的拼图人机验证、右滑拼图验证

安装vue-puzzle-vcode

 npm install vue-puzzle-vcode --save

使用vue-puzzle-vcode

import Vcode from "vue-puzzle-vcode";

<Vcode :show="isShow" @success="onSuccess" @close="onClose" />

自己使用插件的dom

<template>
  <div class="login-container">
    <div class="login-card">
        <div class="fonz">手机验证码</div>
        <div class="flex" style="padding-right: ">
          <input
            type="text"
            placeholder="请输入手机验证码"
            style="padding-left: 0px !important"
          />
          <span
            style="color: rgba(90, 181, 242, 1); font-size: 14px"
            @click="sendCode"
            >{{ codeButtonText }}</span
          >
        </div>
      </div>
      <Vcode :show="isShow" @success="onSuccess" @close="isShow = false" />
  </div>
</template>

<script>
import Vcode from "vue-puzzle-vcode";
export default {
  components: {
    Vcode,
  },
  data() {
    return {
      isShow: false,
    };
  },
  methods: {
 
    // 发送验证码
    sendCode() {
      console.log(this.codeSending);
      if (!this.codeSending) {
        this.isShow = true;
      }
    },
    onSuccess(msg) {
      this.isShow = false; // 通过验证后,需要手动关闭模态框
      // 实现发送验证码的逻辑
      // 可以使用定时器模拟发送过程
      this.codeSending = true;
      let count = 60;
      const timer = setInterval(() => {
        count--;
        if (count === 0) {
          clearInterval(timer);
          this.codeSending = false;
          this.codeButtonText = "重新获取";
        } else {
          this.codeButtonText = `重新获取 ${count}s`;
        }
      }, 1000);
    },
  },
};
</script>

<style lang="scss" scoped>
.hh {
  font-size: 20px;
  font-weight: 700;
  line-height: 23px;
  color: rgba(51, 51, 51, 1);
  text-align: center;
  vertical-align: top;
  margin-bottom: 20px;
  height: 30px;
}
input {
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  padding: 0;
  margin: 0;
  border-radius: 0;
  outline: none;
  flex: 1;
  padding-left: 20px !important;
}
.flex {
  display: flex;
  align-items: center;
  height: 30px;
  justify-content: space-between;
  margin-bottom: 30px;
  border-bottom: 2px solid rgba(227, 227, 227, 1);
}
.fonz {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0px;
  line-height: 19.21px;
  color: rgba(31, 32, 38, 1);
  text-align: left;
  vertical-align: top;
  margin-bottom: 17px;
}
::v-deep {
  .el-checkbox__inner::after {
    left: 5px;
    top: 2px;
  }
  .el-checkbox__inner {
    width: 17px;
    height: 17px;
    border-radius: 8px;
  }
  .el-checkbox__inner:hover {
    border-color: #dcdfe6 !important;
  }
  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #28b0a6 !important;
  }

  .el-checkbox__input.is-checked .el-checkbox__inner {
    background-color: #28b0a6;
  }
  .el-menu-item:hover {
    background-color: #f6f6f6 !important;
  }
  .el-tabs__nav-wrap::after {
    display: none !important;
  }
  .el-tabs__item:hover {
    color: #28b0a6 !important;
    cursor: pointer;
  }

  .el-tabs__item.is-active {
    color: #28b0a6;
  }

  .el-tabs__active-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background-color: #28b0a6 !important;
    z-index: 1;
    transition: transform 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
    list-style: none;
  }
}
.login-container {
  background-color: #f6f6f6;
  display: flex;
  width: 100vw;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-image: url("../.././assets/backc.png");
  // background-size: cover;
  background-repeat: no-repeat;
}

.login-card {
  position: fixed;
  left: 1297px;
  top: 204px;
  width: 385px;
  padding: 47px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.login-title {
  margin-bottom: 20px;
  font-size: 24px;
  font-weight: bold;
  text-align: center;
}
.login-button {
  width: 100%;
  margin-bottom: 20px;
  background-color: #28b0a6;
}

.login-links {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 8px;
  margin-bottom: 48px;
  font-size: 14px;
  font-weight: 400;

  a {
    color: rgba(90, 181, 242, 1);
    text-align: center;
    vertical-align: middle;
    text-decoration: none;
  }
}

.register-link,
.forgot-password-link {
  color: #666;
}
.agreement {
  font-size: 14px;
  span {
    margin-left: 10px;
  }
  a {
    font-size: 14px;
    font-weight: 400;
    color: rgba(90, 181, 242, 1);
    text-align: center;
    text-decoration: none;
  }
}
</style>


在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
滑动验证码是一种常见的人机验证方式,可以有效地防止机器人恶意攻击。下面是一个使用Python编写滑动验证码示例: 首先,我们需要导入必要的模块,包括selenium、PIL和time: ```python from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from PIL import Image import time ``` 接下来,我们需要启动Chrome浏览器,并打开目标网站: ```python driver = webdriver.Chrome() driver.get('https://www.example.com') ``` 然后,我们需要找到滑块验证码图片的元素,并获取它们的位置和大小信息: ```python slider = driver.find_element_by_xpath('//div[@class="slider"]') slider_width = slider.size['width'] slider_height = slider.size['height'] captcha = driver.find_element_by_xpath('//div[@class="captcha"]') captcha_left = captcha.location['x'] captcha_top = captcha.location['y'] captcha_right = captcha_left + captcha.size['width'] captcha_bottom = captcha_top + captcha.size['height'] ``` 接着,我们需要截取验证码图片,并保存到本地: ```python driver.save_screenshot('screenshot.png') captcha_image = Image.open('screenshot.png') captcha_image = captcha_image.crop((captcha_left, captcha_top, captcha_right, captcha_bottom)) captcha_image.save('captcha.png') ``` 然后,我们需要使用PIL库来加载验证码图片,并找到滑块的初始位置: ```python captcha_image = Image.open('captcha.png') slider_image = captcha_image.crop((0, 0, slider_width, slider_height)) slider_image.save('slider.png') slider_start = (slider.location['x'] - captcha_left, slider.location['y'] - captcha_top) ``` 接下来,我们需要使用selenium模拟鼠标拖动滑块的操作,直到滑块到达指定位置: ```python slider_knob = driver.find_element_by_xpath('//div[@class="slider-knob"]') while True: slider_image = Image.open('slider.png') captcha_image = Image.open('captcha.png') diff = ImageChops.difference(slider_image, captcha_image) bbox = diff.getbbox() if bbox is None: break offset = (bbox[0] + slider_start[0], bbox[1] + slider_start[1]) actions = ActionChains(driver) actions.click_and_hold(slider_knob).move_by_offset(offset[0], offset[1]).release().perform() time.sleep(1) ``` 最后,我们可以关闭浏览器,并删除临时文件: ```python driver.quit() os.remove('screenshot.png') os.remove('captcha.png') os.remove('slider.png') ``` 完整的Python代码示例如下:

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值