Compare commits
11 Commits
password-f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 515745451b | |||
| a21693fd0b | |||
| 12aad793c6 | |||
| b5de9852ca | |||
| 143be4a33a | |||
| 22f58ff478 | |||
| cf37859078 | |||
| 409e4ae98f | |||
| 978974f012 | |||
| a23222a026 | |||
| a1fdfa0a41 |
36
README.md
Normal file
36
README.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# PassMetric
|
||||
|
||||
### Temat projektu: Analizator haseł
|
||||
|
||||
### Opis:
|
||||
PassMetric to narzędzie służące do
|
||||
kompleksowej oceny bezpieczeństwa wprowadzonych haseł. Aplikacja
|
||||
natychmiastowo analizuje hasło pod kątem siły, sprawdzając takie
|
||||
kryteria jak długość, różnorodność znaków (duże/małe litery, cyfry, symbole) i
|
||||
brak typowych słów słownikowych. Ponadto, kluczową funkcjonalnością jest weryfikacja,
|
||||
czy hasło nie wyciekło wcześniej w wyniku naruszeń danych. Ostatecznym celem aplikacji
|
||||
jest dostarczenie użytkownikowi natychmiastowej informacji zwrotnej i wskazówek,
|
||||
które pomogą mu stworzyć silne i unikalne zabezpieczenie konta.
|
||||
|
||||
|
||||
### Założenia:
|
||||
- [x] Sprawdza ile hasło będzie łamane przy pomocy metody Bruteforce (Andrii Solianyk)
|
||||
- [x] Sprawdza czy hasło nie wyciekło (Patryk Kania)
|
||||
- [x] Sprawdza jego złożoność (Hubert Salwa)
|
||||
- [x] Proponuje zmiany hasła w celu poprawy jego złożoności (Hubert Salwa)
|
||||
- [x] Statystyki złożoności (Andrii Solianyk)
|
||||
|
||||
---
|
||||
### Skład zespołu:
|
||||
|
||||
- Andrii Solianyk
|
||||
- Patryk Kania
|
||||
- Hubert Salwa
|
||||
|
||||
### Do statystyk:
|
||||
|
||||
Wypisywanie dodatkowych informacji na temat statystyk liter w tym haslie.
|
||||
|
||||
Raport przygotowany w formie dokumentu, rozbudowane sprawozdanie
|
||||
- wstęp teoretyczny
|
||||
- implementacja
|
||||
@@ -1,5 +1,9 @@
|
||||
package iz._11a.passmetric;
|
||||
|
||||
import iz._11a.passmetric.model.PasswordLeakResult;
|
||||
import iz._11a.passmetric.service.BruteForceService;
|
||||
import iz._11a.passmetric.service.PasswordLeakService;
|
||||
import iz._11a.passmetric.service.PasswordStatisticsService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -8,6 +12,12 @@ import java.util.*;
|
||||
@Controller
|
||||
public class PasswordController {
|
||||
|
||||
private final PasswordLeakService passwordLeakService;
|
||||
|
||||
public PasswordController(PasswordLeakService passwordLeakService) {
|
||||
this.passwordLeakService = passwordLeakService;
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
public String home() {
|
||||
return "password";
|
||||
@@ -15,17 +25,21 @@ public class PasswordController {
|
||||
|
||||
@PostMapping(path = "/api/password/strength")
|
||||
@ResponseBody
|
||||
public Map<String, Object> checkPasswordLive(@RequestParam("password") String password) {
|
||||
public Map<String, Object> checkPasswordLive(@RequestBody String password) {
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
|
||||
int score = calculateScore(password);
|
||||
String strengthText = strengthText(score);
|
||||
List<String> tips = generateTips(password);
|
||||
PasswordLeakResult leakResult = passwordLeakService.checkLeakWithCount(password);
|
||||
|
||||
response.put("strengthText", strengthText);
|
||||
response.put("progress", score * 20); // pasek postępu 0–100%
|
||||
response.put("tips", tips);
|
||||
response.put("leaked", leakResult.isLeaked() ? "Hasło wyciekło " + leakResult.getCount() +" razy" : "Hasło nie występuje w wyciekach");
|
||||
response.put("timetohack", BruteForceService.estimateTimeToHackFormatted(password));
|
||||
response.put("stats", PasswordStatisticsService.getPasswordStatistics(password));
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -73,7 +87,7 @@ public class PasswordController {
|
||||
if (!password.matches(".*[0-9].*"))
|
||||
tips.add("Dodaj co najmniej jedną cyfre.");
|
||||
if (!password.matches(".*[@$!%*?&#].*"))
|
||||
tips.add("Dodaj co najmniej jeden znnak specjalny (np. ! @ # $).");
|
||||
tips.add("Dodaj co najmniej jeden znak specjalny (np. ! @ # $).");
|
||||
if (password.length() < 12)
|
||||
tips.add("Wydłuż hasło do co najmniej 12 znaków.");
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package iz._11a.passmetric.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PasswordLeakResult {
|
||||
public final boolean leaked;
|
||||
public final int count;
|
||||
|
||||
public PasswordLeakResult(boolean leaked, int count) {
|
||||
this.leaked = leaked;
|
||||
this.count = count;
|
||||
}
|
||||
}
|
||||
131
src/main/java/iz/_11a/passmetric/service/BruteForceService.java
Normal file
131
src/main/java/iz/_11a/passmetric/service/BruteForceService.java
Normal file
@@ -0,0 +1,131 @@
|
||||
package iz._11a.passmetric.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class BruteForceService {
|
||||
|
||||
private static final long ATTEMPTS_PER_SECOND = 1_000_000_000L;
|
||||
|
||||
private static final int LOWERCASE_SIZE = 26; // a-z
|
||||
private static final int UPPERCASE_SIZE = 26; // A-Z
|
||||
private static final int DIGITS_SIZE = 10; // 0-9
|
||||
private static final int SPECIAL_CHARS_SIZE = 32; // !@#$%^&*() и т.д.
|
||||
|
||||
private static final BigDecimal SECONDS_IN_MINUTE = BigDecimal.valueOf(60);
|
||||
private static final BigDecimal SECONDS_IN_HOUR = SECONDS_IN_MINUTE.multiply(BigDecimal.valueOf(60));
|
||||
private static final BigDecimal SECONDS_IN_DAY = SECONDS_IN_HOUR.multiply(BigDecimal.valueOf(24));
|
||||
private static final BigDecimal SECONDS_IN_YEAR = SECONDS_IN_DAY.multiply(new BigDecimal("365.25"));
|
||||
|
||||
public static String estimateTimeToHackFormatted(String password) {
|
||||
int charsetSize = calculateCharsetSize(password);
|
||||
if (charsetSize == 0) {
|
||||
return "nie można oszacować czasu dla pustego hasła";
|
||||
}
|
||||
int passwordLength = password.length();
|
||||
|
||||
BigDecimal totalCombinations = BigDecimal.valueOf(charsetSize).pow(passwordLength);
|
||||
BigDecimal averageAttempts = totalCombinations.divide(BigDecimal.valueOf(2.0), RoundingMode.HALF_UP);
|
||||
|
||||
return formatTime(averageAttempts.divide(BigDecimal.valueOf(ATTEMPTS_PER_SECOND), 10, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
|
||||
|
||||
public static String formatTime(double seconds) {
|
||||
if (seconds < 1.0) {
|
||||
return "mniej niż sekundę";
|
||||
}
|
||||
|
||||
BigDecimal totalSeconds = BigDecimal.valueOf(seconds);
|
||||
BigDecimal[] yearsAndRemainder = totalSeconds.divideAndRemainder(SECONDS_IN_YEAR);
|
||||
long years = yearsAndRemainder[0].longValue();
|
||||
|
||||
if (years > 1_000_000_000L) {
|
||||
return "∞ (nieskończenie długo)";
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
if (years > 0) {
|
||||
result.append(years).append(" ").append(getYearsForm(years)).append(" ");
|
||||
}
|
||||
|
||||
BigDecimal[] daysAndRemainder = yearsAndRemainder[1].divideAndRemainder(SECONDS_IN_DAY);
|
||||
long days = daysAndRemainder[0].longValue();
|
||||
if (days > 0) {
|
||||
result.append(days).append(" ").append(getDaysForm(days)).append(" ");
|
||||
}
|
||||
|
||||
BigDecimal[] hoursAndRemainder = daysAndRemainder[1].divideAndRemainder(SECONDS_IN_HOUR);
|
||||
long hours = hoursAndRemainder[0].longValue();
|
||||
if (hours > 0) {
|
||||
result.append(hours).append(" ").append(getHoursForm(hours)).append(" ");
|
||||
}
|
||||
|
||||
BigDecimal[] minutesAndRemainder = hoursAndRemainder[1].divideAndRemainder(SECONDS_IN_MINUTE);
|
||||
long minutes = minutesAndRemainder[0].longValue();
|
||||
if (minutes > 0) {
|
||||
result.append(minutes).append(" ").append(getMinutesForm(minutes)).append(" ");
|
||||
}
|
||||
|
||||
long remainingSeconds = minutesAndRemainder[1].setScale(0, RoundingMode.HALF_UP).longValue();
|
||||
if (remainingSeconds > 0) {
|
||||
result.append(remainingSeconds).append(" ").append(getSecondsForm(remainingSeconds));
|
||||
}
|
||||
|
||||
return result.toString().trim();
|
||||
}
|
||||
|
||||
|
||||
private static String getYearsForm(long years) {
|
||||
if (years == 1) return "rok";
|
||||
if (years % 10 >= 2 && years % 10 <= 4 && (years % 100 < 10 || years % 100 >= 20)) return "lata";
|
||||
return "lat";
|
||||
}
|
||||
|
||||
private static String getDaysForm(long days) {
|
||||
if (days == 1) return "dzień";
|
||||
return "dni";
|
||||
}
|
||||
|
||||
private static String getHoursForm(long hours) {
|
||||
if (hours == 1) return "godzina";
|
||||
if (hours % 10 >= 2 && hours % 10 <= 4 && (hours % 100 < 10 || hours % 100 >= 20)) return "godziny";
|
||||
return "godzin";
|
||||
}
|
||||
|
||||
private static String getMinutesForm(long minutes) {
|
||||
if (minutes == 1) return "minuta";
|
||||
if (minutes % 10 >= 2 && minutes % 10 <= 4 && (minutes % 100 < 10 || minutes % 100 >= 20)) return "minuty";
|
||||
return "minut";
|
||||
}
|
||||
|
||||
private static String getSecondsForm(long seconds) {
|
||||
if (seconds == 1) return "sekunda";
|
||||
if (seconds % 10 >= 2 && seconds % 10 <= 4 && (seconds % 100 < 10 || seconds % 100 >= 20)) return "sekundy";
|
||||
return "sekund";
|
||||
}
|
||||
|
||||
|
||||
private static int calculateCharsetSize(String password) {
|
||||
int charsetSize = 0;
|
||||
boolean hasLowercase = false;
|
||||
boolean hasUppercase = false;
|
||||
boolean hasDigits = false;
|
||||
boolean hasSpecial = false;
|
||||
|
||||
for (char c : password.toCharArray()) {
|
||||
if (Character.isLowerCase(c)) hasLowercase = true;
|
||||
else if (Character.isUpperCase(c)) hasUppercase = true;
|
||||
else if (Character.isDigit(c)) hasDigits = true;
|
||||
else hasSpecial = true;
|
||||
}
|
||||
|
||||
if (hasLowercase) charsetSize += LOWERCASE_SIZE;
|
||||
if (hasUppercase) charsetSize += UPPERCASE_SIZE;
|
||||
if (hasDigits) charsetSize += DIGITS_SIZE;
|
||||
if (hasSpecial) charsetSize += SPECIAL_CHARS_SIZE;
|
||||
|
||||
return charsetSize;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package iz._11a.passmetric.service;
|
||||
|
||||
import iz._11a.passmetric.model.PasswordLeakResult;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClient;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
@Service
|
||||
public class PasswordLeakService {
|
||||
|
||||
private final RestClient restClient;
|
||||
|
||||
public PasswordLeakService(RestClient.Builder builder) {
|
||||
this.restClient = builder
|
||||
.baseUrl("https://api.pwnedpasswords.com")
|
||||
.defaultHeader(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN_VALUE)
|
||||
.defaultHeader(HttpHeaders.USER_AGENT, "passmetric/1.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
public PasswordLeakResult checkLeakWithCount(String password) {
|
||||
if (password == null || password.isEmpty()) {
|
||||
return new PasswordLeakResult(false, 0);
|
||||
}
|
||||
String sha1 = sha1Hex(password).toUpperCase();
|
||||
String prefix = sha1.substring(0, 5);
|
||||
String suffix = sha1.substring(5);
|
||||
|
||||
try {
|
||||
String body = restClient.get()
|
||||
.uri("/range/{prefix}", prefix)
|
||||
.retrieve()
|
||||
.body(String.class);
|
||||
|
||||
if (body == null || body.isEmpty()) {
|
||||
return new PasswordLeakResult(false, 0);
|
||||
}
|
||||
|
||||
for (String line : body.split("\n")) {
|
||||
String[] parts = line.split(":");
|
||||
if (parts.length == 2 && parts[0].equalsIgnoreCase(suffix)) {
|
||||
int count = Integer.parseInt(parts[1].trim());
|
||||
return new PasswordLeakResult(true, count);
|
||||
}
|
||||
}
|
||||
return new PasswordLeakResult(false, 0);
|
||||
} catch (RestClientException ex) {
|
||||
return new PasswordLeakResult(false, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLeaked(String password) {
|
||||
return checkLeakWithCount(password).isLeaked();
|
||||
}
|
||||
|
||||
private String sha1Hex(String input) {
|
||||
try {
|
||||
var md = java.security.MessageDigest.getInstance("SHA-1");
|
||||
byte[] digest = md.digest(input.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
StringBuilder sb = new StringBuilder(digest.length * 2);
|
||||
for (byte b : digest) sb.append(String.format("%02x", b));
|
||||
return sb.toString();
|
||||
} catch (java.security.NoSuchAlgorithmException e) {
|
||||
throw new IllegalStateException("SHA-1 not available", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package iz._11a.passmetric.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PasswordStatisticsService {
|
||||
|
||||
public static Map<String, Object> getPasswordStatistics(String password) {
|
||||
Map<String, Object> stats = new HashMap<>();
|
||||
|
||||
if (password == null || password.isEmpty()) {
|
||||
stats.put("length", 0);
|
||||
stats.put("lowercaseCount", 0);
|
||||
stats.put("uppercaseCount", 0);
|
||||
stats.put("digitCount", 0);
|
||||
stats.put("specialCount", 0);
|
||||
return stats;
|
||||
}
|
||||
|
||||
int lowercaseCount = 0;
|
||||
int uppercaseCount = 0;
|
||||
int digitCount = 0;
|
||||
int specialCount = 0;
|
||||
|
||||
for (char c : password.toCharArray()) {
|
||||
if (Character.isLowerCase(c)) {
|
||||
lowercaseCount++;
|
||||
} else if (Character.isUpperCase(c)) {
|
||||
uppercaseCount++;
|
||||
} else if (Character.isDigit(c)) {
|
||||
digitCount++;
|
||||
} else {
|
||||
specialCount++;
|
||||
}
|
||||
}
|
||||
|
||||
stats.put("length", password.length());
|
||||
stats.put("lowercaseCount", lowercaseCount);
|
||||
stats.put("uppercaseCount", uppercaseCount);
|
||||
stats.put("digitCount", digitCount);
|
||||
stats.put("specialCount", specialCount);
|
||||
|
||||
return stats;
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ body {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 24px;
|
||||
align-content: space-evenly;
|
||||
}
|
||||
|
||||
h1 {
|
||||
@@ -59,7 +60,7 @@ h1 {
|
||||
}
|
||||
|
||||
form {
|
||||
width: min(92vw, 480px);
|
||||
width: min(92vw, 540px);
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
padding: 20px 18px;
|
||||
@@ -117,8 +118,8 @@ input[type="password"]:focus {
|
||||
}
|
||||
}
|
||||
|
||||
#liveMessage {
|
||||
width: min(92vw, 480px);
|
||||
.message {
|
||||
width: min(92vw, 540px);
|
||||
margin: 12px auto 0;
|
||||
padding: 12px 14px;
|
||||
border-radius: 12px;
|
||||
@@ -129,55 +130,157 @@ input[type="password"]:focus {
|
||||
font-size: 14px;
|
||||
transition: all 200ms ease;
|
||||
opacity: 1;
|
||||
min-height: 47px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
#liveMessage {
|
||||
.message {
|
||||
background: rgba(30, 41, 59, 0.75);
|
||||
border-color: rgba(203, 213, 225, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Hide when empty */
|
||||
#liveMessage:empty {
|
||||
display: none;
|
||||
.message:empty {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
#liveMessage.ok {
|
||||
.message.ok {
|
||||
border-color: var(--ok);
|
||||
background: color-mix(in oklab, var(--ok) 20%, rgba(241, 245, 249, 0.85));
|
||||
color: #15803d;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
#liveMessage.ok {
|
||||
.message.ok {
|
||||
background: color-mix(in oklab, var(--ok) 18%, rgba(30, 41, 59, 0.75));
|
||||
color: #86efac;
|
||||
}
|
||||
}
|
||||
|
||||
#liveMessage.warn {
|
||||
.message.warn {
|
||||
border-color: var(--warn);
|
||||
background: color-mix(in oklab, var(--warn) 20%, rgba(241, 245, 249, 0.85));
|
||||
color: #c2410c;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
#liveMessage.warn {
|
||||
.message.warn {
|
||||
background: color-mix(in oklab, var(--warn) 18%, rgba(30, 41, 59, 0.75));
|
||||
color: #fdba74;
|
||||
}
|
||||
}
|
||||
|
||||
#liveMessage.bad {
|
||||
.message.bad {
|
||||
border-color: var(--bad);
|
||||
background: color-mix(in oklab, var(--bad) 20%, rgba(241, 245, 249, 0.85));
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
#liveMessage.bad {
|
||||
.message.bad {
|
||||
background: color-mix(in oklab, var(--bad) 18%, rgba(30, 41, 59, 0.75));
|
||||
color: #fca5a5;
|
||||
}
|
||||
}
|
||||
|
||||
#strengthBarContainer {
|
||||
width: min(92vw, 540px);
|
||||
margin: 10px auto 0;
|
||||
height: 10px;
|
||||
background: #e2e8f0;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#strengthBarFill {
|
||||
height: 100%;
|
||||
width: 0;
|
||||
background: var(--bad);
|
||||
transition: width 200ms ease, background-color 200ms ease;
|
||||
}
|
||||
|
||||
ul#tipsList {
|
||||
width: min(92vw, 540px);
|
||||
margin: 10px auto 0;
|
||||
padding-left: 20px;
|
||||
font-size: 14px;
|
||||
color: var(--text);
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
ul#tipsList.ok {
|
||||
padding-left: 14px;
|
||||
list-style: none;
|
||||
color: #86efac;
|
||||
}
|
||||
|
||||
ul#tipsList li {
|
||||
margin: 0.3rem 0.5rem;
|
||||
}
|
||||
|
||||
/*stats*/
|
||||
|
||||
.stats-container {
|
||||
width: min(92vw, 540px);
|
||||
margin: 16px auto 0;
|
||||
padding: 16px;
|
||||
border-radius: 12px;
|
||||
border: 1.5px solid var(--border);
|
||||
background: var(--panel);
|
||||
backdrop-filter: blur(12px);
|
||||
display: none;
|
||||
}
|
||||
|
||||
.stats-title {
|
||||
margin: 0 0 12px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: var(--text);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 8px 12px;
|
||||
background: rgba(148, 163, 184, 0.1);
|
||||
border-radius: 8px;
|
||||
transition: background 160ms ease;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.stat-item {
|
||||
background: rgba(51, 65, 85, 0.4);
|
||||
}
|
||||
}
|
||||
|
||||
.stat-item:hover {
|
||||
background: rgba(148, 163, 184, 0.15);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.stat-item:hover {
|
||||
background: rgba(51, 65, 85, 0.6);
|
||||
}
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 13px;
|
||||
color: var(--muted);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,32 +5,6 @@
|
||||
<title>PassMetric</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" th:href="@{/css/password.css}">
|
||||
<style>
|
||||
/* Pasek siły hasła – dopasowany do Twojego stylu */
|
||||
#strengthBarContainer {
|
||||
width: min(92vw, 480px);
|
||||
margin: 10px auto 0;
|
||||
height: 10px;
|
||||
background: #e2e8f0;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#strengthBarFill {
|
||||
height: 100%;
|
||||
width: 0%;
|
||||
background: var(--bad);
|
||||
transition: width 200ms ease, background-color 200ms ease;
|
||||
}
|
||||
|
||||
ul#tipsList {
|
||||
width: min(92vw, 480px);
|
||||
margin: 10px auto 0;
|
||||
padding-left: 20px;
|
||||
font-size: 14px;
|
||||
color: var(--text);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Sprawdź siłę hasła</h1>
|
||||
@@ -45,17 +19,55 @@
|
||||
<div id="strengthBarFill"></div>
|
||||
</div>
|
||||
|
||||
<!-- Główny komunikat (słabe, średnie, silne itd.) -->
|
||||
<p id="liveMessage" aria-live="polite"></p>
|
||||
<div id="statsContainer" class="stats-container">
|
||||
<h3 class="stats-title">Statystyki hasła</h3>
|
||||
<div class="stats-grid">
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Długość:</span>
|
||||
<span class="stat-value" id="statLength">-</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Małe litery:</span>
|
||||
<span class="stat-value" id="statLowercase">-</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Wielkie litery:</span>
|
||||
<span class="stat-value" id="statUppercase">-</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Cyfry:</span>
|
||||
<span class="stat-value" id="statDigits">-</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Znaki specjalne:</span>
|
||||
<span class="stat-value" id="statSpecial">-</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Podpowiedzi krok po kroku -->
|
||||
<ul id="tipsList"></ul>
|
||||
|
||||
<div class="message-wrapper">
|
||||
<p id="liveMessage" class="message" aria-live="polite"></p>
|
||||
<p id="leakMessage" class="message" aria-live="polite"></p>
|
||||
<p id="timeToHackMessage" class="message" aria-live="polite"></p>
|
||||
<ul id="tipsList" class="message" aria-live="polite">
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const input = document.getElementById('password');
|
||||
const out = document.getElementById('liveMessage');
|
||||
const bar = document.getElementById('strengthBarFill');
|
||||
const barContainer = document.getElementById('strengthBarContainer');
|
||||
const tipsList = document.getElementById('tipsList');
|
||||
const leakOut = document.getElementById('leakMessage');
|
||||
const timeToHackOut = document.getElementById('timeToHackMessage');
|
||||
const statsContainer = document.getElementById('statsContainer');
|
||||
|
||||
// ukryj przy pierwszym załadowaniu strony
|
||||
tipsList.style.display = 'none';
|
||||
barContainer.style.display = 'none';
|
||||
|
||||
let t;
|
||||
input.addEventListener('input', () => {
|
||||
@@ -64,9 +76,15 @@
|
||||
|
||||
if (!val) {
|
||||
out.textContent = '';
|
||||
out.className = '';
|
||||
out.className = 'message';
|
||||
leakOut.textContent = '';
|
||||
leakOut.className = 'message';
|
||||
bar.style.width = "0%";
|
||||
tipsList.innerHTML = '';
|
||||
barContainer.style.display = 'none';
|
||||
tipsList.innerHTML = "";
|
||||
tipsList.style.display = 'none';
|
||||
timeToHackOut.textContent = '';
|
||||
statsContainer.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -74,20 +92,17 @@
|
||||
try {
|
||||
const resp = await fetch('/api/password/strength', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: new URLSearchParams({ password: val })
|
||||
headers: {'Content-Type': 'text/plain'},
|
||||
body: val,
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
out.textContent = 'Błąd sprawdzania';
|
||||
leakOut.textContent = '';
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await resp.json();
|
||||
|
||||
// Ustawiamy tekst siły hasła
|
||||
out.textContent = data.strengthText || '';
|
||||
out.className = '';
|
||||
out.className = 'message';
|
||||
|
||||
switch (data.strengthText) {
|
||||
case "Bardzo słabe hasło":
|
||||
@@ -95,39 +110,89 @@
|
||||
bar.style.background = "var(--bad)";
|
||||
break;
|
||||
case "Słabe hasło":
|
||||
out.classList.add("warn");
|
||||
bar.style.background = "var(--warn)";
|
||||
break;
|
||||
case "Średnie hasło":
|
||||
out.classList.add("warn");
|
||||
bar.style.background = "var(--warn)";
|
||||
break;
|
||||
case "Silne hasło":
|
||||
out.classList.add("ok");
|
||||
bar.style.background = "var(--ok)";
|
||||
break;
|
||||
case "Bardzo silne hasło":
|
||||
out.classList.add("ok");
|
||||
bar.style.background = "var(--ok)";
|
||||
break;
|
||||
}
|
||||
|
||||
// Pasek postępu (0–100%)
|
||||
if (data.leaked) {
|
||||
leakOut.textContent = data.leaked || '';
|
||||
leakOut.className = 'message';
|
||||
switch (data.leaked) {
|
||||
case "Hasło wyciekło!":
|
||||
leakOut.classList.add("bad");
|
||||
break;
|
||||
case "Hasło nie występuje w wyciekach":
|
||||
leakOut.classList.add("ok");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bar.style.width = (data.progress || 0) + "%";
|
||||
barContainer.style.display = 'block';
|
||||
|
||||
// Podpowiedzi
|
||||
tipsList.innerHTML = "";
|
||||
(data.tips || []).forEach(tip => {
|
||||
if (data.tips && data.tips.length > 0) {
|
||||
if (data.tips.length === 1 && data.tips[0] === "Świetnie! Twoje hasło jest bardzo silne.") {
|
||||
tipsList.textContent = data.tips[0];
|
||||
tipsList.classList.add("ok");
|
||||
tipsList.style.display = 'block';
|
||||
} else {
|
||||
tipsList.classList.remove("ok");
|
||||
data.tips.forEach(tip => {
|
||||
const li = document.createElement("li");
|
||||
li.textContent = tip;
|
||||
tipsList.appendChild(li);
|
||||
});
|
||||
tipsList.style.display = 'block';
|
||||
}
|
||||
} else {
|
||||
tipsList.style.display = 'none';
|
||||
}
|
||||
|
||||
// TimeToHack
|
||||
timeToHackOut.textContent = "Zostanie złamane w: " + (data.timetohack || '');
|
||||
timeToHackOut.className = 'message';
|
||||
|
||||
if (data.timetohack && data.timetohack.includes("nieskończenie długo")) {
|
||||
timeToHackOut.classList.add("ok");
|
||||
} else if (data.timetohack && data.timetohack.includes("mniej")) {
|
||||
timeToHackOut.classList.add("bad")
|
||||
} else {
|
||||
timeToHackOut.classList.remove("ok");
|
||||
}
|
||||
|
||||
// stats
|
||||
if (data.stats) {
|
||||
document.getElementById('statLength').textContent = data.stats.length || 0;
|
||||
document.getElementById('statLowercase').textContent =
|
||||
data.stats.lowercaseCount || 0;
|
||||
document.getElementById('statUppercase').textContent =
|
||||
data.stats.uppercaseCount || 0;
|
||||
document.getElementById('statDigits').textContent =
|
||||
data.stats.digitCount || 0;
|
||||
document.getElementById('statSpecial').textContent =
|
||||
data.stats.specialCount || 0;
|
||||
|
||||
statsContainer.style.display = 'block';
|
||||
} else {
|
||||
statsContainer.style.display = 'none';
|
||||
}
|
||||
|
||||
} catch {
|
||||
out.textContent = 'Błąd sieci';
|
||||
leakOut.textContent = '';
|
||||
}
|
||||
}, 150);
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user