Initial commit

This commit is contained in:
2025-10-18 10:41:36 +02:00
commit 983c860b26
13 changed files with 939 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package iz._11a.passmetric;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class PassMetricApplication {
public static void main(String[] args) {
SpringApplication.run(PassMetricApplication.class, args);
}
}

View File

@@ -0,0 +1,39 @@
package iz._11a.passmetric;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@Controller
public class PasswordController {
@GetMapping("/")
public String home() {
return "password";
}
@PostMapping(path = "/api/password/strength")
@ResponseBody
public Map<String, String> checkPasswordLive(@RequestParam("password") String password) {
return Map.of("message", analyze(password));
}
private String analyze(String password) {
int score = 0;
if (password != null) {
if (password.matches(".*[a-z].*")) score++;
if (password.matches(".*[A-Z].*")) score++;
if (password.matches(".*[0-9].*")) score++;
if (password.matches(".*[@$!%*?&#].*")) score++;
if (password.length() >= 8) score++;
}
return switch (score) {
case 5 -> "Bardzo silne hasło";
case 4 -> "Silne hasło";
case 3 -> "Średnie hasło";
case 2 -> "Słabe hasło";
default -> "Bardzo słabe hasło";
};
}
}

View File

@@ -0,0 +1 @@
spring.application.name=PassMetric

View File

@@ -0,0 +1,184 @@
:root {
--bg-1: #f0f4ff;
--bg-2: #e0e7ff;
--glow-1: #a5b4fc;
--glow-2: #93c5fd;
--panel: rgba(255, 255, 255, 0.96);
--text: #1e293b;
--muted: #64748b;
--border: rgba(15, 23, 42, 0.16);
--primary: #2563eb;
--primary-600: #1d4ed8;
--ok: #16a34a;
--warn: #ea580c;
--bad: #dc2626;
}
@media (prefers-color-scheme: dark) {
:root {
--bg-1: #0f172a;
--bg-2: #1e293b;
--glow-1: #1e3a8a;
--glow-2: #0c4a6e;
--panel: rgba(30, 41, 59, 0.85);
--text: #f1f5f9;
--muted: #cbd5e1;
--border: rgba(203, 213, 225, 0.3);
--primary: #3b82f6;
--primary-600: #2563eb;
}
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
margin: 0;
font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Inter, Arial, sans-serif;
color: var(--text);
background:
radial-gradient(1200px 600px at 10% -20%, var(--glow-1) 0%, transparent 40%),
radial-gradient(1200px 600px at 120% 120%, var(--glow-2) 0%, transparent 40%),
linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%);
display: grid;
place-items: center;
padding: 24px;
}
h1 {
margin: 0 0 14px;
font-size: clamp(22px, 3vw, 28px);
font-weight: 700;
letter-spacing: -0.02em;
text-align: center;
color: var(--text);
}
form {
width: min(92vw, 480px);
background: var(--panel);
border: 1px solid var(--border);
padding: 20px 18px;
border-radius: 16px;
backdrop-filter: blur(12px);
box-shadow:
0 10px 30px rgba(2, 6, 23, 0.15),
0 2px 6px rgba(2, 6, 23, 0.08);
}
label {
display: block;
margin: 0 0 8px;
font-size: 13px;
font-weight: 600;
letter-spacing: 0.02em;
color: var(--muted);
}
input[type="password"] {
width: 100%;
padding: 12px 14px;
border-radius: 12px;
border: 1.5px solid var(--border);
background: #f9fafb; /* delikatniejszy biały */
color: #111827; /* ciemniejszy, ale łagodniejszy tekst */
font-size: 15px;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}
@media (prefers-color-scheme: dark) {
input[type="password"] {
background: #273449; /* jaśniejsze tło */
color: #f1f5f9;
border-color: rgba(203, 213, 225, 0.3); /* lekko jaśniejszy border */
}
}
input[type="password"]:hover {
border-color: color-mix(in oklab, var(--primary) 40%, var(--border));
}
input[type="password"]:focus {
border-color: var(--primary);
box-shadow:
0 0 0 3px color-mix(in oklab, var(--primary) 20%, transparent),
0 4px 12px rgba(37, 99, 235, 0.15);
background: #ffffff;
}
@media (prefers-color-scheme: dark) {
input[type="password"]:focus {
background: #0f172a;
}
}
/* Live region message */
#liveMessage {
width: min(92vw, 480px);
margin: 12px auto 0;
padding: 12px 14px;
border-radius: 12px;
border: 1.5px solid var(--border);
background: rgba(241, 245, 249, 0.85);
color: var(--text);
font-weight: 500;
font-size: 14px;
transition: all 200ms ease;
opacity: 1;
}
@media (prefers-color-scheme: dark) {
#liveMessage {
background: rgba(30, 41, 59, 0.75);
border-color: rgba(203, 213, 225, 0.2);
}
}
/* Hide when empty */
#liveMessage:empty {
display: none;
}
#liveMessage.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 {
background: color-mix(in oklab, var(--ok) 18%, rgba(30, 41, 59, 0.75));
color: #86efac;
}
}
#liveMessage.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 {
background: color-mix(in oklab, var(--warn) 18%, rgba(30, 41, 59, 0.75));
color: #fdba74;
}
}
#liveMessage.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 {
background: color-mix(in oklab, var(--bad) 18%, rgba(30, 41, 59, 0.75));
color: #fca5a5;
}
}

View File

@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="pl" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>PassMetric</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" th:href="@{/css/password.css}">
</head>
<body>
<h1>Sprawdź siłę hasła</h1>
<form>
<label for="password">Hasło</label>
<input type="password" id="password" autocomplete="off">
</form>
<p id="liveMessage" aria-live="polite"></p>
<script>
const input = document.getElementById('password');
const out = document.getElementById('liveMessage');
let t;
input.addEventListener('input', () => {
clearTimeout(t);
const val = input.value;
if (!val) { out.textContent = ''; return; }
t = setTimeout(async () => {
try {
const resp = await fetch('/api/password/strength', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ password: val })
});
if (!resp.ok) { out.textContent = 'Błąd sprawdzania'; return; }
const data = await resp.json();
out.textContent = data.message || '';
out.className = '';
switch (data.message) {
case "Bardzo słabe hasło":
out.classList.add("bad");
break;
case "Słabe hasło":
out.classList.add("warn");
break;
case "Średnie hasło":
out.classList.add("warn");
break;
case "Silne hasło":
out.classList.add("ok");
break;
case "Bardzo silne hasło":
out.classList.add("ok");
break;
}
} catch {
out.textContent = 'Błąd sieci';
}
}, 150);
});
</script>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="pl" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Wynik analizy hasła</title>
</head>
<body>
<h2 th:text="${message}">Wynik analizy</h2>
<a href="/">Powrót</a>
</body>
</html>