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
- User submits email and password
- Account is created (unverified)
- Verification email is sent
- User clicks verification link
- Account is marked as verified
- User can sign in
Password Reset Flow
- User requests password reset
- Reset password email verification link is sent
- User clicks link and is redirected back to the app
- User submits new password
- Old password is changed to the new one
- User receives confirmation email
- User can sign in with new password
Email Change Flow
- User requests email change
- Email change verification link is sent
- User clicks link and is redirected back to the app
- User submits new email
- Old email is changed to the new one
- User receives confirmation email to both old and new email addresses
- User can sign in with new email
