Resetowanie hasła i weryfikacja adresu e-mail
Twórz bezpieczne procesy odzyskiwania konta i weryfikacji adresu e-mail, używając jednorazowych tokenów, wygasania oraz transakcyjnej poczty e-mail, aby użytkownicy mogli bezpiecznie odzyskać dostęp.
Resetowanie hasła i weryfikacja adresu e-mail to bezpłatna lekcja AI Powered SaaS: Stripe + Auth + Billing + Deploy na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej AI Powered SaaS: Stripe + Auth + Billing + Deploy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs AI Powered SaaS: Stripe + Auth + Billing + Deploy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
Why Reset & Verify?
Users forget passwords and mistype emails. A safe password reset flow lets them recover without support, and email verification confirms the address really belongs to them, cutting spam and fake accounts.
The Token Strategy
Both flows rely on a one-time token: a random, unguessable string emailed to the user. Possessing it proves control of the inbox.
import crypto from 'crypto';
const token = crypto.randomBytes(32).toString('hex');Storing the Token Hashed
Never store the raw token. Hash it before saving so a database leak cannot be used to reset accounts. Compare hashes when the user returns.
const hash = crypto.createHash('sha256').update(token).digest('hex');
await prisma.resetToken.create({
data: { userId, hash, expiresAt }
});Adding Expiry
Tokens must expire — usually 15 to 60 minutes. Store an expiresAt timestamp and reject tokens past it.
const expiresAt = new Date(Date.now() + 30 * 60 * 1000);Requesting a Reset
The user submits their email. Generate a token, save its hash, and email a link containing the raw token. Always respond the same way to avoid leaking which emails exist.
const link = process.env.APP_URL + '/reset?token=' + token;
await sendEmail(email, 'Reset your password', link);Sending Transactional Email
Use a provider like Resend or SendGrid for reliable delivery. Keep the message short with a clear single action.
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
await resend.emails.send({ to, subject, html });Verifying the Token
When the user opens the link, hash the incoming token, look it up, and check it is unused and unexpired.
const hash = crypto.createHash('sha256').update(token).digest('hex');
const record = await prisma.resetToken.findFirst({
where: { hash, expiresAt: { gt: new Date() }, usedAt: null }
});Updating the Password
If valid, hash the new password and save it, then mark the token used so it cannot be replayed.
const pw = await bcrypt.hash(newPassword, 12);
await prisma.user.update({ where: { id: record.userId }, data: { password: pw } });
await prisma.resetToken.update({ where: { id: record.id }, data: { usedAt: new Date() } });Email Verification Flow
Verification works the same way: on signup, email a token. When clicked, set emailVerified on the user and invalidate the token.
await prisma.user.update({
where: { id }, data: { emailVerified: new Date() }
});Preventing Abuse
Protect these endpoints:
- Rate limit reset requests
- Give identical responses for known and unknown emails
- Allow only one active token per user
Best Practices
Build recovery securely:
- Use random, hashed tokens with expiry
- Send via a transactional email provider
- Mark tokens used after one use
- Rate limit and avoid email enumeration
Quick Check
Test your reset-flow knowledge.
Recap
You built account recovery:
- Generate random tokens, store them hashed with expiry
- Email links via a transactional provider
- Verify, then update the password and mark the token used
- Reuse the pattern for email verification and guard against abuse
Users can now safely recover and verify accounts.
Często zadawane pytania
Czy lekcja „Resetowanie hasła i weryfikacja adresu e-mail” jest bezpłatna?
Tak — pełny tekst „Resetowanie hasła i weryfikacja adresu e-mail” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu AI Powered SaaS: Stripe + Auth + Billing + Deploy, przejdź na CoddyKit PRO. Kurs AI Powered SaaS: Stripe + Auth + Billing + Deploy zawiera 4 lekcji w sumie.
Co nauczysz się w „Resetowanie hasła i weryfikacja adresu e-mail”?
Twórz bezpieczne procesy odzyskiwania konta i weryfikacji adresu e-mail, używając jednorazowych tokenów, wygasania oraz transakcyjnej poczty e-mail, aby użytkownicy mogli bezpiecznie odzyskać dostęp. Ćwiczysz AI Powered SaaS: Stripe + Auth + Billing + Deploy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć AI Powered SaaS: Stripe + Auth + Billing + Deploy?
Nie wymagamy żadnego doświadczenia. AI Powered SaaS: Stripe + Auth + Billing + Deploy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Resetowanie hasła i weryfikacja adresu e-mail”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji AI Powered SaaS: Stripe + Auth + Billing + Deploy?
Tak. Każda lekcja AI Powered SaaS: Stripe + Auth + Billing + Deploy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Rejestracja użytkowników i haszowanie
- Logowanie i generowanie JWT
- Chronione trasy i middleware
- Resetowanie hasła i weryfikacja adresu e-mail