App Logo
Plugins

Email & Password

Standalone Mode

Configure the plugin in your config.toml:

[plugins.email_password]
enabled = true
min_password_length = 8
max_password_length = 128
disable_sign_up = false
require_email_verification = true
auto_sign_in = true
send_email_on_sign_up = true
send_email_on_sign_in = false
email_verification_expires_in = "24h"
password_reset_expires_in = "1h"
request_email_change_expires_in = "1h"

Library Mode

package main

import (
	"context"
	"log"
	"net/http"
	"os"

	authula "github.com/Authula/authula"
	authulaconfig "github.com/Authula/authula/config"
	authulamodels "github.com/Authula/authula/models"
	emailpasswordplugin "github.com/Authula/authula/plugins/email-password"
	emailpasswordplugintypes "github.com/Authula/authula/plugins/email-password/types"
)

func main() {
	config := authulaconfig.NewConfig(
		authulaconfig.WithAppName("YourAppName"),
		authulaconfig.WithDatabase(authulamodels.DatabaseConfig{
			Provider:         "postgres",
			URL: os.Getenv("DATABASE_URL"),
		}),
	)
	auth := authula.New(&authula.AuthConfig{
		Config:  config,
		Plugins: [
			emailpasswordplugin.New(emailpasswordplugintypes.EmailPasswordPluginConfig{
				Enabled:                  true,
				MinPasswordLength:        8,
				MaxPasswordLength:        32,
				DisableSignUp:            false,
				RequireEmailVerification: true,
				AutoSignIn:               true,
				SendEmailOnSignUp:        true,
				// optional: custom email sending logic
				SendEmailVerification: func(
					params emailpasswordplugintypes.SendEmailVerificationParams,
					reqCtx *authulamodels.RequestContext,
				) error {
					// Implement your email sending logic here
					return nil
				},
			}),
		],
	})

	log.Fatal(http.ListenAndServe(":8080", auth.Handler()))
}

User Registration Flow

  1. User submits email and password
  2. Account is created (unverified)
  3. Verification email is sent
  4. User clicks verification link
  5. Account is marked as verified
  6. User can sign in

Password Reset Flow

  1. User requests password reset
  2. Reset password email verification link is sent
  3. User clicks link and is redirected back to the app
  4. User submits new password
  5. Old password is changed to the new one
  6. User receives confirmation email
  7. User can sign in with new password

Email Change Flow

  1. User requests email change
  2. Email change verification link is sent
  3. User clicks link and is redirected back to the app
  4. User submits new email
  5. Old email is changed to the new one
  6. User receives confirmation email to both old and new email addresses
  7. User can sign in with new email

On this page