当前位置: 首页 > 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>

http://www.lryc.cn/news/398045.html

相关文章:

  • WPS打开PDF文件的目录
  • 常见 Web漏洞分析与防范研究
  • 暗黑魅力:Xcode全面拥抱应用暗黑模式开发指南
  • 【游戏引擎之路】登神长阶(七)——x86汇编学习:凡做难事,必有所得
  • 在 Windows 平台搭建 MQTT 服务
  • jdevelope安装
  • 排序(一)——冒泡排序、直接插入排序、希尔排序(BubbleSOrt,InsertSort,ShellSort)
  • synchronized关键字详解(全面分析)
  • 数据建设实践之大数据平台(三)
  • TypeScript中的交叉类型
  • CNN -1 神经网络-概述2
  • 利用js实现图片压缩功能
  • 2024.7.10 刷题总结
  • ES6 async 函数详解 (十)
  • 【安全设备】入侵检测
  • 07浅谈大语言模型可调节参数tempreture
  • Redis数据同步
  • 快手矩阵源码,快速拥有自己的短视频矩阵
  • notes for datawhale 2th summer camp NLP task1
  • 攻防世界(PHP过滤器过滤)file_include
  • PostGIS2.4服务器编译安装
  • 虚拟机安装Linux CENTOS 07 部署NET8 踩坑大全
  • 【C++】CMake入门
  • 云WAF | 云waf保护你的网络安全
  • c++初阶知识——类和对象(1)
  • Vue 3 组件通信全解:从基础到高级技巧
  • 大众汽车入职SHL在线测评、英语口语、招聘笔试如何通过、考点分析|备考建议
  • 《植物大战僵尸杂交版》2.2:新版本体验与下载指南
  • 7月11日学习打卡,数据结构栈
  • 数据结构第20节 快速排序以及优化