Skip to content

Commit 7cda26e

Browse files
authored
Merge pull request #213 from nagasaisriya/add-passwordgenerator
added password_generator app
2 parents afebc43 + e7f8fbe commit 7cda26e

File tree

6 files changed

+258
-0
lines changed

6 files changed

+258
-0
lines changed

Index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@
7878
| [Tindog](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/Tindog) | Tinder customized for dogs to find their mate online |
7979
| [Word counter App](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/word%20counter) | Simple Word counter App written in HTML, CSS, and JavaScript
8080
| [Chess Game](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/Chess-Game) | A basic chess game for entertainment purpose. |
81+
| [Password Generator](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/Password%20Generator) | A password generator app to generate strong passwords which can be easily used for authentication. |
8182
| [Parallex Website](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/Chess-Game) | A basic website using HTML, CSS, JAVASCRIPT with modern look. |
83+

Password Generator/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<h1>Password Generator App</h1>
2+
3+
<p>Password Generator App written in HTML, CSS, and JavaScript .</p>
4+
5+
### Use of the Project:
6+
7+
<p>This app helps to create strong random passwords which can be easily used during authentication.</p>
8+
9+
<h3>Used Technologies</h3>
10+
<ul>
11+
<li>HTML5</li>
12+
<li>CSS3</li>
13+
<li>JavaScript</li>
14+
</ul>
15+
16+
#### Steps to Use:
17+
18+
---
19+
20+
- Download or clone the repository
21+
22+
```
23+
git clone https://github.com/Ayushparikh-code/Web-dev-mini-projects.git
24+
```
25+
26+
- Go to the directory
27+
- Run the index.html file
28+
- Start Calculating!!
29+
30+
<h3> ScreenShots </h3>
31+
32+
<img width="750" alt="Password Generator" src="https://user-images.githubusercontent.com/63009472/125650386-c89c969a-85ac-4807-b5fe-ee299ffd2083.png">
33+
34+
<br>
35+
36+

Password Generator/index.html

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css"
8+
integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog=="
9+
crossorigin="anonymous" />
10+
<link rel="stylesheet" href="style.css" />
11+
<script src="https://cdnjs.cloudflare.com/ajax/libs/vanilla-tilt/1.7.0/vanilla-tilt.min.js"></script>
12+
<title>Password Generator</title>
13+
</head>
14+
15+
<body>
16+
<div class="card">
17+
<div class="container">
18+
<h2>Password Generator</h2>
19+
<div class="result-container">
20+
<span id="result"></span>
21+
<button class="btn" id="clipboard">
22+
<i class="far fa-clipboard"></i>
23+
</button>
24+
</div>
25+
<div class="settings">
26+
<div class="setting">
27+
<label>Password Length</label>
28+
<input type="number" id="length" min="4" max="20" value="20">
29+
</div>
30+
<div class="setting">
31+
<label>Include uppercase letters</label>
32+
<input type="checkbox" id="uppercase" checked>
33+
</div>
34+
<div class="setting">
35+
<label>Include lowercase letters</label>
36+
<input type="checkbox" id="lowercase" checked>
37+
</div>
38+
<div class="setting">
39+
<label>Include numbers</label>
40+
<input type="checkbox" id="numbers" checked>
41+
</div>
42+
<div class="setting">
43+
<label>Include symbols</label>
44+
<input type="checkbox" id="symbols" checked>
45+
</div>
46+
</div>
47+
</div>
48+
<button class="btn btn-large" id="generate">
49+
Generate Password
50+
</button>
51+
52+
</div>
53+
<script src="script.js"></script>
54+
55+
</body>
56+
57+
</html>
58+

Password Generator/screenshot.png

50.4 KB
Loading

Password Generator/script.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const resultEl = document.getElementById('result')
2+
const lengthEl = document.getElementById('length')
3+
const uppercaseEl = document.getElementById('uppercase')
4+
const lowercaseEl = document.getElementById('lowercase')
5+
const numbersEl = document.getElementById('numbers')
6+
const symbolsEl = document.getElementById('symbols')
7+
const generateEl = document.getElementById('generate')
8+
const clipboardEl = document.getElementById('clipboard')
9+
10+
const randomFunc = {
11+
lower: getRandomLower,
12+
upper: getRandomUpper,
13+
number: getRandomNumber,
14+
symbol: getRandomSymbol
15+
}
16+
17+
clipboardEl.addEventListener('click', () => {
18+
const textarea = document.createElement('textarea')
19+
const password = resultEl.innerText
20+
21+
if(!password) { return }
22+
23+
textarea.value = password
24+
document.body.appendChild(textarea)
25+
textarea.select()
26+
document.execCommand('copy')
27+
textarea.remove()
28+
alert('Password copied to clipboard!')
29+
})
30+
31+
generateEl.addEventListener('click', () => {
32+
const length = +lengthEl.value
33+
const hasLower = lowercaseEl.checked
34+
const hasUpper = uppercaseEl.checked
35+
const hasNumber = numbersEl.checked
36+
const hasSymbol = symbolsEl.checked
37+
38+
resultEl.innerText = generatePassword(hasLower, hasUpper, hasNumber, hasSymbol, length)
39+
})
40+
41+
function generatePassword(lower, upper, number, symbol, length) {
42+
let generatedPassword = ''
43+
const typesCount = lower + upper + number + symbol
44+
const typesArr = [{lower}, {upper}, {number}, {symbol}].filter(item => Object.values(item)[0])
45+
46+
if(typesCount === 0) {
47+
return ''
48+
}
49+
50+
for(let i = 0; i < length; i += typesCount) {
51+
typesArr.forEach(type => {
52+
const funcName = Object.keys(type)[0]
53+
generatedPassword += randomFunc[funcName]()
54+
})
55+
}
56+
57+
const finalPassword = generatedPassword.slice(0, length)
58+
59+
return finalPassword
60+
}
61+
62+
function getRandomLower() {
63+
return String.fromCharCode(Math.floor(Math.random() * 26) + 97)
64+
}
65+
66+
function getRandomUpper() {
67+
return String.fromCharCode(Math.floor(Math.random() * 26) + 65)
68+
}
69+
70+
function getRandomNumber() {
71+
return String.fromCharCode(Math.floor(Math.random() * 10) + 48)
72+
}
73+
74+
function getRandomSymbol() {
75+
const symbols = '!@#$%^&*(){}[]=<>/,.'
76+
return symbols[Math.floor(Math.random() * symbols.length)]
77+
}
78+

Password Generator/style.css

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
2+
3+
* {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
background-color: #3b4498;
9+
color: rgb(255, 255, 255);
10+
font-family: 'Muli';
11+
font-weight: 500;
12+
display: flex;
13+
flex-direction: column;
14+
align-items: center;
15+
justify-content: center;
16+
height: 100vh;
17+
overflow: hidden;
18+
padding: 10px;
19+
margin: 0;
20+
}
21+
22+
h2 {
23+
margin: 10px 0 20px;
24+
text-align: center;
25+
font-weight: 1000;
26+
}
27+
28+
.container {
29+
background-color: #7a4fac;
30+
box-shadow: 0px 2px 10px rgba(255, 255, 255, 0.2);
31+
padding: 20px;
32+
width: 350px;
33+
max-width: 100%;
34+
}
35+
36+
.result-container {
37+
background-color: rgba(0, 0, 0, 0.247);
38+
display: flex;
39+
justify-content: flex-start;
40+
align-items: center;
41+
position: relative;
42+
font-size: 18px;
43+
font-weight: bold;
44+
letter-spacing: 1px;
45+
padding: 12px 10px;
46+
height: 50px;
47+
width: 100%;
48+
}
49+
50+
.result-container #result {
51+
word-wrap: break-word;
52+
max-width: calc(100% - 40px);
53+
}
54+
55+
.result-container .btn {
56+
position: absolute;
57+
top: 5px;
58+
right: 5px;
59+
width: 40px;
60+
height: 40px;
61+
font-size: 20px;
62+
}
63+
64+
.btn {
65+
border: none;
66+
background-color: #2c085c;
67+
color: #fff;
68+
font-size: 16px;
69+
padding: 8px 12px;
70+
cursor: pointer;
71+
}
72+
73+
.btn-large {
74+
display: block;
75+
width: 100%;
76+
}
77+
78+
.setting {
79+
display: flex;
80+
justify-content: space-between;
81+
align-items: center;
82+
margin: 15px 0;
83+
}
84+

0 commit comments

Comments
 (0)