当前位置: 首页 > news >正文

html+css+js随机验证码

随机画入字符、线条  源代码在图片后面

点赞❤️+关注😍+收藏⭐️  互粉必回

图示

ec6bfd2cf73f424bb35056649a0bca69.jpg

 源代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Captcha Verification</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-color: #f0f0f0;
            margin: 0;
        }

        .captcha-container {
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 400px;
        }

        .captcha-board {
            width: 100%;
            height: 150px;
            background: #eee;
            border-radius: 5px;
            position: relative;
            overflow: hidden;
        }

        .captcha-input {
            width: 100%;
            height: 40px;
            margin-top: 20px;
            padding: 0 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

        .captcha-button {
            width: 100%;
            height: 40px;
            background-color: orange;
            color: white;
            border: none;
            border-radius: 5px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            cursor: pointer;
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="captcha-container">
        <div class="captcha-board" id="captchaBoard"></div>
        <input type="text" class="captcha-input" placeholder="Enter the captcha" id="captchaInput">
        <button class="captcha-button" οnclick="verifyCaptcha()">Verify</button>
    </div>

    <script>
        function generateCaptcha() {
            let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
            let captchaText = '';
            for (let i = 0; i < 4; i++) {
                captchaText += chars[Math.floor(Math.random() * chars.length)];
            }
            document.getElementById('captchaBoard').innerHTML = `<h1 style="font-size: 60px;">${captchaText}</h1>`;
            drawRandomLines();
            return captchaText;
        }

        function drawRandomLines() {
            let board = document.getElementById('captchaBoard');
            let svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
            svg.setAttribute("width", "100%");
            svg.setAttribute("height", "100%");
            svg.style.position = "absolute";
            svg.style.top = "0";
            svg.style.left = "0";

            for (let i = 0; i < 10; i++) {
                let line = document.createElementNS("http://www.w3.org/2000/svg", "line");
                let color = `rgb(${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)})`;
                line.setAttribute("x1", Math.random() * 100 + "%");
                line.setAttribute("y1", Math.random() * 100 + "%");
                line.setAttribute("x2", Math.random() * 100 + "%");
                line.setAttribute("y2", Math.random() * 100 + "%");
                line.setAttribute("stroke", color);
                line.setAttribute("stroke-width", 1);
                svg.appendChild(line);
            }
            board.appendChild(svg);
        }

        let captcha = generateCaptcha();

        function verifyCaptcha() {
            let input = document.getElementById('captchaInput').value;
            if (input === captcha) {
                alert('Verification Passed!');
            } else {
                alert('Incorrect Captcha!');
            }
        }
    </script>
</body>
</html>

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 文学式开发工具 Jupyter Notebook
  • 设计模式探索:观察者模式
  • vue draggable组件,拖拽元素时,获取元素上在data或setup中定义的数据
  • 【matlab】随机森林客户流失预测
  • Java之网络面试经典题(一)
  • hcip暑假第二次作业
  • Elasticsearch 更新指定字段
  • C++类和对象(一)
  • C++ 定时器触发
  • 苹果电脑可以玩魔兽世界吗 魔兽世界有mac版本么 macbook 可以玩魔兽世界吗
  • Codeforces Round 957 (Div. 3)(A~E题解)
  • Flutter【组件】标签
  • 【数据结构】初探数据结构面纱:栈和队列全面剖析
  • uniapp中使用uni-ui组件库
  • NLP任务中三个概念标记、样本映射和偏移映射三个概念的浅析
  • JS 中的深拷贝与浅拷贝
  • 《Javascript数据结构和算法》笔记-「字典和散列表」
  • 2017年终总结、随想
  • conda常用的命令
  • create-react-app项目添加less配置
  • Date型的使用
  • ES6之路之模块详解
  • fetch 从初识到应用
  • JavaScript 奇技淫巧
  • niucms就是以城市为分割单位,在上面 小区/乡村/同城论坛+58+团购
  • php面试题 汇集2
  • yii2中session跨域名的问题
  • 阿里云容器服务区块链解决方案全新升级 支持Hyperledger Fabric v1.1
  • 百度贴吧爬虫node+vue baidu_tieba_crawler
  • 成为一名优秀的Developer的书单
  • 互联网大裁员:Java程序员失工作,焉知不能进ali?
  • 使用 Docker 部署 Spring Boot项目
  • 微信开源mars源码分析1—上层samples分析
  • 微信小程序实战练习(仿五洲到家微信版)
  • 小程序上传图片到七牛云(支持多张上传,预览,删除)
  • ​configparser --- 配置文件解析器​
  • ​LeetCode解法汇总518. 零钱兑换 II
  • ​软考-高级-系统架构设计师教程(清华第2版)【第9章 软件可靠性基础知识(P320~344)-思维导图】​
  • # 详解 JS 中的事件循环、宏/微任务、Primise对象、定时器函数,以及其在工作中的应用和注意事项
  • (DFS + 剪枝)【洛谷P1731】 [NOI1999] 生日蛋糕
  • (zt)最盛行的警世狂言(爆笑)
  • (简单) HDU 2612 Find a way,BFS。
  • (接口封装)
  • (九)c52学习之旅-定时器
  • (四)linux文件内容查看
  • (一) 初入MySQL 【认识和部署】
  • (中等) HDU 4370 0 or 1,建模+Dijkstra。
  • .NET C# 使用 SetWindowsHookEx 监听鼠标或键盘消息以及此方法的坑
  • .net wcf memory gates checking failed
  • .Net 高效开发之不可错过的实用工具
  • .NetCore发布到IIS
  • .net生成的类,跨工程调用显示注释
  • /tmp目录下出现system-private文件夹解决方法
  • /usr/lib/mysql/plugin权限_给数据库增加密码策略遇到的权限问题
  • @modelattribute注解用postman测试怎么传参_接口测试之问题挖掘