Overview
Email/password authentication is a traditional authentication method that allows users to sign up and sign in using their email address and password. SuperTokens Core implements secure password hashing using BCrypt or Argon2 algorithms and provides comprehensive password reset flows.Sign Up
Create a new user account with email and password.Implementation
The sign-up process is implemented inio.supertokens.emailpassword.EmailPassword.signUp() - View source
Key Features:
- Email normalization and validation
- Secure password hashing (BCrypt or Argon2)
- Automatic duplicate email detection
- Support for fake emails (auto-verified)
- Multi-tenancy support
Password Hashing
Passwords are hashed using one of two algorithms: BCrypt:password_hashing_alg: Choose betweenBCRYPTorARGON2bcrypt_log_rounds: BCrypt cost factor (default: 11)argon2_iterations: Number of iterations for Argon2 (default: 1)argon2_memory_kb: Memory cost in KB (default: 87795)argon2_parallelism: Parallelism factor (default: 2)
API Endpoint
POST/recipe/signup
Request Body:
Sign In
Authenticate an existing user with email and password.Implementation
The sign-in process is implemented inio.supertokens.emailpassword.EmailPassword.signIn() - View source
Process:
- Retrieve user by email
- Verify password against stored hash
- Support for multiple password hashing formats (BCrypt, Argon2, Firebase SCrypt)
- Return user information on success
Password Verification
The system supports multiple password hash formats:- BCrypt: Identified by
$2a$,$2b$, or$2y$prefix - Argon2: Identified by
$argon2id$,$argon2i$, or$argon2d$prefix - Firebase SCrypt: For imported users from Firebase
API Endpoint
POST/recipe/signin
Request Body:
Password Reset
Secure password reset flow using time-limited tokens.Generate Password Reset Token
Implementation:io.supertokens.emailpassword.EmailPassword.generatePasswordResetToken() - View source
Token Generation Process:
- Generate 64 bytes of random data
- Generate 64 bytes of salt
- Apply PBKDF2 with 1000 iterations
- Convert to Base64 URL-safe format
- Hash with SHA-256 for storage
- Store with expiry time (default: 1 hour)
/recipe/user/password/reset/token
Request Body:
Consume Password Reset Token
Implementation:io.supertokens.emailpassword.EmailPassword.consumeResetPasswordToken() - View source
Validation Process:
- Hash the provided token with SHA-256
- Look up token in database
- Verify token hasn’t expired
- Delete all tokens for the user
- Return user ID and email
/recipe/user/password/reset/token/consume
Request Body:
Reset Password
Implementation:io.supertokens.emailpassword.EmailPassword.resetPassword() - View source
API Endpoint:
POST /recipe/user/password/reset
Request Body:
Update User
Update user email or password.Implementation
Implementation:io.supertokens.emailpassword.EmailPassword.updateUsersEmailOrPassword() - View source
Features:
- Update email with duplicate check
- Update password with re-hashing
- Account linking validation
- Transaction-based updates
/recipe/user
Request Body:
Import Users
Import users from other systems with existing password hashes.Supported Hash Formats
- BCrypt: Standard BCrypt hashes
- Argon2: Argon2id, Argon2i, Argon2d variants
- Firebase SCrypt: Custom Firebase password hashing
Implementation
Implementation:io.supertokens.emailpassword.EmailPassword.importUserWithPasswordHash() - View source
API Endpoint:
POST /recipe/user/import
Request Body:
Configuration
Password Hashing Settings
Password Reset Settings
Security Features
Password Storage
- Never stored in plaintext: All passwords are hashed before storage
- Salt included: BCrypt and Argon2 automatically include unique salts
- Configurable cost: Adjust hashing parameters based on security requirements
Concurrency Control
- Bounded queues: Argon2 and Firebase SCrypt use bounded queues to prevent resource exhaustion
- Thread-safe: All hashing operations are thread-safe
Email Normalization
All emails are normalized:- Converted to lowercase
- Whitespace trimmed
- Validation performed
Error Handling
Common Exceptions
DuplicateEmailException: Email already existsWrongCredentialsException: Invalid email/password combinationResetPasswordInvalidTokenException: Token expired or invalidUnknownUserIdException: User not foundEmailChangeNotAllowedException: Email change conflicts with account linkingUnsupportedPasswordHashingFormatException: Invalid password hash format
Best Practices
- Use Argon2: More secure than BCrypt for modern applications
- Enforce password policies: Minimum length, complexity requirements
- Rate limiting: Implement rate limiting on sign-in attempts
- Email verification: Verify email addresses after signup
- HTTPS only: Always use HTTPS for authentication endpoints
- Token expiry: Keep password reset token lifetime short (e.g., 1 hour)
- Multi-factor authentication: Consider adding MFA for enhanced security
Multi-Tenancy Support
All email/password operations support multi-tenancy:- Users are isolated by tenant
- Each tenant can have different password hashing configurations
- Email uniqueness enforced per tenant
- Account linking respects tenant boundaries