Reimpostazione della password e verifica dell’email
Crei flussi sicuri per il recupero dell’account e la verifica dell’email usando token monouso, scadenze ed email transazionali, così gli utenti possono recuperare l’accesso in sicurezza.
Reimpostazione della password e verifica dell’email è una lezione AI Powered SaaS: Stripe + Auth + Billing + Deploy gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento AI Powered SaaS: Stripe + Auth + Billing + Deploy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso AI Powered SaaS: Stripe + Auth + Billing + Deploy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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.
Domande Frequenti
La lezione «Reimpostazione della password e verifica dell’email» è gratuita?
Sì — il testo completo di «Reimpostazione della password e verifica dell’email» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso AI Powered SaaS: Stripe + Auth + Billing + Deploy, passa a CoddyKit PRO. Il corso AI Powered SaaS: Stripe + Auth + Billing + Deploy include 4 lezioni in totale.
Cosa imparerò in «Reimpostazione della password e verifica dell’email»?
Crei flussi sicuri per il recupero dell’account e la verifica dell’email usando token monouso, scadenze ed email transazionali, così gli utenti possono recuperare l’accesso in sicurezza. Eserciti AI Powered SaaS: Stripe + Auth + Billing + Deploy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare AI Powered SaaS: Stripe + Auth + Billing + Deploy?
Non è richiesta alcuna esperienza precedente. AI Powered SaaS: Stripe + Auth + Billing + Deploy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Reimpostazione della password e verifica dell’email»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione AI Powered SaaS: Stripe + Auth + Billing + Deploy?
Sì. Ogni lezione AI Powered SaaS: Stripe + Auth + Billing + Deploy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Registrazione degli utenti e hashing
- Login e generazione di JWT
- Route protette e middleware
- Reimpostazione della password e verifica dell’email