<div class="passContainer">
<h2>Random Password Generator App</h2>
<div class="randomPass">
<input type="text" name="" id="passwordShow" placeholder="" readonly/>
</div>
<div class="randomBtn">
<button type="submit" onclick="randomPassword()">Generate Password </button>
</div>
<button type="submit" class="copy" onclick="copyText()"><i class="fas fa-clipboard"></i></button>
</div>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
min-height: 100vh;
background: #fff;
display: flex;
justify-content: center;
align-items: center;
}
.passContainer{
position: relative;
width: 400px;
min-height: 200px;
background: #fff;
border: 2px solid #E9E9EF;
border-radius: 12px;
box-shadow: rgba(0, 0, 0, 0.15) 2.4px 2.4px 3.2px;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.passContainer h2{
width: 350px;
color: #38BFF4;
margin: 20px auto;
text-align: center;
font-family: system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.passContainer .randomPass{
width: 300px;
height: 50px;
position: relative;
/* width: 100%;
height: 100%;*/
border-radius: 8px;
padding: 8px 18px;
margin-bottom: 20px;
box-shadow: rgb(204, 219, 232) 3px 3px 6px 0px inset, rgba(255, 255, 255, 0.5) -3px -4px 6px 1px inset;
}
.passContainer .randomPass input{
width: 100%;
height: 100%;
border: none;
letter-spacing: 7px;
color: #38BFF4;
font-weight: 900;
font-size: 14px;
font-family: monospace;
outline: none;
}
.passContainer .randomBtn{
width: 340px;
height: 50px;
position: relative;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
margin-bottom: 20px;
}
.passContainer .randomBtn button{
width: 220px;
height: 40px;
text-align: center;
border: none;
border-radius: 8px;
background: #38BFF4;
color: #fff;
font-weight: 800;
font-size: 16px;
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
letter-spacing: 1px;
outline: none;
cursor: pointer;
}
button:hover{
background: #1E7FA5;
}
.copy{
position: absolute;
width: 40px;
height: 40px;
right: 5px;
top: 42%;
border-radius: 8px;
border: none;
color: #fff;
background: #38BFF4;
font-size: 1.5em;
cursor: pointer;
z-index: 10;
}
.copy:hover{
color: #38bff4;
background: #1E929D;
}
let show_pass = document.getElementById('passwordShow');
function randomPassword(){
//using math.random function for printing 0 to 9
//tostring function for 0 to 9 an a to z
const password = Math.random().toString(36).slice(2) + Math.random().toString(36).toUpperCase().slice(2);
show_pass.value = password;
}
//function for copy text
function copyText(){
//using inbuilt select function
show_pass.select();
//.execCommand to use copy text
document.execCommand('copy');
alert('Password is copied');
}
This Pen doesn't use any external JavaScript resources.