-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sentence based password.html
61 lines (49 loc) · 2.03 KB
/
Sentence based password.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sentence-Based Password Generator</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="sstyle.css">
</head>
<body>
<div class="container mt-5">
<h1 class="text-center mb-4">Sentence-Based Password Generator</h1>
<div class="form-group">
<label for="sentenceInput">Enter a Sentence:</label>
<input type="text" class="form-control" id="sentenceInput" placeholder="E.g., I love to read books!">
</div>
<button class="btn btn-primary" onclick="generatePassword()">Generate Password</button>
<div class="mt-3">
<strong>Generated Password:</strong>
<p id="generatedPassword" class="mt-2"></p>
</div>
</div>
<script>
function generatePassword() {
const sentenceInput = document.getElementById('sentenceInput').value;
if (!sentenceInput) {
alert('Please enter a sentence.');
return;
}
const password = generateSentenceBasedPassword(sentenceInput);
document.getElementById('generatedPassword').textContent = password;
}
function generateSentenceBasedPassword(sentence) {
const words = sentence.split(' ');
let password = '';
words.forEach(word => {
if (word.length > 2) {
password += word.charAt(0).toUpperCase() + word.slice(1);
}
});
const randomNumber = Math.floor(Math.random() * 100);
const specialCharacter = String.fromCharCode(33 + (randomNumber % 14)); // ASCII values for special characters
password += specialCharacter;
password += randomNumber.toString().padStart(2, '0');
return password;
}
</script>
</body>
</html>