OTP Generate

Home / Web Code Snippet / OTP Generate

OTP Generate


https://youtube.com/shorts/7wic0qKFvvM?si=vJBSQr7hDMMr4kL-

HTML CODE:-

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
</head>
<body>
<div class="container">
    <p>Your OTP Is:- <span></span></p>
    <button onclick="generateOTP()">Generate OTP</button>
</div>
</body>
</html>

CSS CODE:-

body{
            padding: 0px;
            margin: 0px;
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            background: black;
        }
        .container{
            position: relative;
            width: 300px;
            height: 150px;
            background: white;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            border: 2px solid blue;
            box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
        }
        .container p{
            font-size: 25px;
            font-weight: 700;
        }
        .container span{
            font-size: 25px;
            font-weight: 700;
            color: darkblue;
        }
        .container button{
            padding: 10px 20px;
            background: transparent;
            color: darkblue;
            border-radius: 10px;
            border: 2px solid darkblue;
            font-weight: 700;
            cursor: pointer;
            transition: 0.5s;
        }
        .container button:hover{
            background: darkblue;
            color: white;
        }

JS CODE:-

function generateOTP(){
        var number = '0123456789';
        let OTP = '';

        for(let i = 0; i<6; i++){
            OTP += number[Math.floor(Math.random() * 10)];
        }

        var span = document.querySelector('.container span')
        span.innerHTML = OTP;
    }