- Published on
What You Need To Make A Password Generator And Strength Score With Tailwind CSS

- What is Tailwind CSS?
- The description of Password Generator and Strength Score ui component
- Why use Tailwind CSS to make a Password Generator and Strength Score ui component?
- The preview of Password Generator and Strength Score ui component
- The source code of Password Generator and Strength Score ui component
- How to make a Password Generator and Strength Score with Tailwind CSS?
- Install tailwind css of verion 2.0.2
- All the unility class needed to make a Password Generator and Strength Score component
- 50 steps to make a Password Generator and Strength Score component with Tailwind CSS
- Conclusion
What is Tailwind CSS?
Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.
The description of Password Generator and Strength Score ui component
Alpinejs password generator with zxcvbn score checker
Why use Tailwind CSS to make a Password Generator and Strength Score ui component?
- It can make the building process of Password Generator and Strength Score ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Password Generator and Strength Score component file.
The preview of Password Generator and Strength Score ui component
Free download of the Password Generator and Strength Score's source code
The source code of Password Generator and Strength Score ui component
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zxcvbn/4.4.2/zxcvbn.js"></script>
<style>@import url(https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/5.3.45/css/materialdesignicons.min.css);</style>
<div class="min-w-screen min-h-screen bg-gray-800 flex items-center justify-center px-5 py-5">
<div class="w-full mx-auto rounded-lg bg-white shadow p-5 text-gray-800" style="max-width: 500px" x-data="app()" x-init="generatePassword()">
<div class="relative mb-2">
<input :type="showPasswordField?'password':'text'" id="password" x-model="password" class="w-full pl-3 pr-10 py-2 border-2 border-gray-200 rounded-md focus:outline-none focus:border-indigo-500 transition-colors" placeholder="Password" @input="checkStrength()">
<button class="block w-7 h-7 text-center text-xl leading-0 absolute top-2 right-2 text-gray-400 focus:outline-none hover:text-indigo-500 transition-colors" @click.prevent="showPasswordField=!showPasswordField"><i class="mdi" :class="`mdi-${showPasswordField?'eye-outline':'eye-off-outline'}`"></i></button>
</div>
<div class="flex -mx-1">
<template x-for="(v,i) in 5">
<div class="w-1/5 px-1">
<div class="h-2 rounded-xl transition-colors" :class="i<passwordScore?(passwordScore<=2?'bg-red-400':(passwordScore<=4?'bg-yellow-400':'bg-green-500')):'bg-gray-200'"></div>
</div>
</template>
</div>
<hr class="my-5 border border-gray-200">
<div class="mb-2">
<label class="block text-xs font-semibold text-gray-500 mb-2">PASSWORD LENGTH</label>
<input class="w-full px-3 py-2 mb-1 border-2 border-gray-200 rounded-md focus:outline-none focus:border-indigo-500 transition-colors" placeholder="Length" type="number" min="1" max="30" step="1" x-model="charsLength" @input="generatePassword()"/>
<input class="w-full" type="range" x-model="charsLength" min="1" max="30" step="1" @input="generatePassword()">
</div>
<div class="flex -mx-2 mb-2">
<div class="w-1/2 px-2">
<label for="charsLower">
<input type="checkbox" class="align-middle" id="charsLower" @input="generatePassword()" checked>
<span class="text-xs font-semibold text-gray-500">LOWERCASE</span>
</label>
</div>
<div class="w-1/2 px-2">
<label for="charsUpper">
<input type="checkbox" class="align-middle" id="charsUpper" @input="generatePassword()" checked>
<span class="text-xs font-semibold text-gray-500">UPPERCASE</span>
</label>
</div>
</div>
<div class="flex -mx-2">
<div class="w-1/2 px-2">
<label for="charsNumeric">
<input type="checkbox" class="align-middle" id="charsNumeric" @input="generatePassword()" checked>
<span class="text-xs font-semibold text-gray-500">NUMBERS</span>
</label>
</div>
<div class="w-1/2 px-2">
<label for="charsSymbols">
<input type="checkbox" class="align-middle" id="charsSymbols" @input="generatePassword()" checked>
<span class="text-xs font-semibold text-gray-500">SYMBOLS</span>
</label>
</div>
</div>
</div>
</div>
<script>
function app(){
return {
showPasswordField: true,
passwordScore: 0,
password: '',
chars: {
lower: 'abcdefghijklmnopqrstuvwxyz',
upper: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
numeric: '0123456789',
symbols: '!"#$%&\'()*+,-./:;<=>[email protected][\\]^_`{|}~'
},
charsLength: 12,
checkStrength: function() {
if(!this.password) return this.passwordScore = 0;
this.passwordScore = zxcvbn(this.password).score + 1;
},
generatePassword: function() {
console.log(document.getElementById('charsSymbols').checked);
this.password = this.shuffleArray(
((document.getElementById('charsLower').checked?this.chars.lower:'')+(document.getElementById('charsUpper').checked?this.chars.upper:'')+(document.getElementById('charsNumeric').checked?this.chars.numeric:'')+(document.getElementById('charsSymbols').checked?this.chars.symbols:'')).split('')
).join('').substring(0, this.charsLength);
this.checkStrength();
},
shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
}
}
</script>
<!-- BUY ME A BEER AND HELP SUPPORT OPEN-SOURCE RESOURCES -->
<div class="flex items-end justify-end fixed bottom-0 right-0 mb-4 mr-4 z-10">
<div>
<a title="Buy me a beer" href="https://www.buymeacoffee.com/scottwindon" target="_blank" class="block w-16 h-16 rounded-full transition-all shadow hover:shadow-lg transform hover:scale-110 hover:rotate-12">
<img class="object-cover object-center w-full h-full rounded-full" src="https://i.pinimg.com/originals/60/fd/e8/60fde811b6be57094e0abc69d9c2622a.jpg"/>
</a>
</div>
</div>
How to make a Password Generator and Strength Score with Tailwind CSS?
Install tailwind css of verion 2.0.2
Use the script
html tag to import the script of Tailwind CSS of the version 2.0.2
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to make a Password Generator and Strength Score component
min-w-screen
min-h-screen
bg-gray-800
flex
px-5
py-5
w-full
mx-auto
bg-white
p-5
text-gray-800
relative
mb-2
pl-3
pr-10
py-2
border-2
border-gray-200
focus:border-indigo-500
block
w-7
h-7
text-center
text-xl
absolute
top-2
right-2
text-gray-400
hover:text-indigo-500
-mx-1
w-1/5
px-1
h-2
my-5
text-xs
text-gray-500
px-3
mb-1
-mx-2
w-1/2
px-2
fixed
bottom-0
right-0
mb-4
mr-4
z-10
w-16
h-16
h-full
50 steps to make a Password Generator and Strength Score component with Tailwind CSS
Set the minimum width/height of an element using the
min-w-screen
utilities.Set the minimum width/height of an element using the
min-h-screen
utilities.Control the background color of an element to gray-800 using the
bg-gray-800
utilities.Use
flex
to create a block-level flex container.Control the horizontal padding of an element to 1.25rem using the
px-5
utilities.Control the vertical padding of an element to 1.25rem using the
py-5
utilities.Use
w-full
to set an element to a 100% based width.Control the horizontal margin of an element to auto using the
mx-auto
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the padding on all sides of an element to 1.25rem using the
p-5
utilities.Control the text color of an element to gray-800 using the
text-gray-800
utilities.Use
relative
to position an element according to the normal flow of the document.Control the margin on bottom side of an element to 0.5rem using the
mb-2
utilities.Adjust the left padding of the element to 0.75rem using the
pl-3
utilities classControl the padding on right side of an element to 2.5rem using the
pr-10
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the border color of an element to 0.5rem using the
border-2
utilities.Control the border color of an element to gray-200 using the
border-gray-200
utilities.Control the border color of an element to indigo-500 using the
focus:border-indigo-500
utilities on focus.Use
inline
utilities to put the element on its own line and fill its parent.Use
w-7
to set an element to a fixed width(1.75rem).Use
h-7
to set an element to a fixed height(1.75rem).Control the text color of an element to center using the
text-center
utilities.Control the text color of an element to xl using the
text-xl
utilities.Use
absolute
to position an element outside of the normal flow of the document, causing neighboring elements to act as if the element doesn’t exist.Use the
top-2
utilities to set the top position of a positioned element to 0.5rem.Use the
right-2
utilities to set the right position of a positioned element to 0.5rem.Control the text color of an element to gray-400 using the
text-gray-400
utilities.Control the text color of an element to indigo-500 on hover using the
hover:text-indigo-500
utilities.Control the horizontal margin of an element to -0.25rem using the
-mx-1
utilities.Use
w-1/5
to set an element to a fixed width(1/5).Control the horizontal padding of an element to 0.25rem using the
px-1
utilities.Use
h-2
to set an element to a fixed height(0.5rem).Control the vertical margin of an element to 1.25rem using the
my-5
utilities.Control the text color of an element to xs using the
text-xs
utilities.Control the text color of an element to gray-500 using the
text-gray-500
utilities.Control the horizontal padding of an element to 0.75rem using the
px-3
utilities.Control the margin on bottom side of an element to 0.25rem using the
mb-1
utilities.Control the horizontal margin of an element to -0.5rem using the
-mx-2
utilities.Use
w-1/2
to set an element to a fixed width(1/2).Control the horizontal padding of an element to 0.5rem using the
px-2
utilities.Use
fixed
to position an element relative to the browser window.Use the
bottom-0
utilities to set the bottom position of a positioned element to 0rem.Use the
right-0
utilities to set the right position of a positioned element to 0rem.Control the margin on bottom side of an element to 1rem using the
mb-4
utilities.Control the margin on right side of an element to 1rem using the
mr-4
utilities.Control the stack order (or three-dimensional positioning) of an element to 10 in Tailwind, regardless of order it has been displayed, using the
z-10
utilities.Use
w-16
to set an element to a fixed width(4rem).Use
h-16
to set an element to a fixed height(4rem).Use
h-full
to set an element’s height to 100% of its parent, as long as the parent has a defined height.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to make a Password Generator and Strength Score components, learn and follow along to implement your own components.