pub struct PasswordAuthPlugin { /* private fields */ }Expand description
Password auth plugin. Stores hashed passwords using Argon2id.
Passwords are hashed with Argon2id (the recommended variant for password hashing). The hash output is a PHC-format string that embeds the salt, algorithm, memory/time parameters, and hash value.
Implementations§
Source§impl PasswordAuthPlugin
impl PasswordAuthPlugin
pub fn new() -> Self
Sourcepub fn register(
&self,
email: &str,
password: &str,
user_id: &str,
) -> Result<(), String>
pub fn register( &self, email: &str, password: &str, user_id: &str, ) -> Result<(), String>
Register a new user with email + password.
Sourcepub fn verify(&self, email: &str, password: &str) -> Option<String>
pub fn verify(&self, email: &str, password: &str) -> Option<String>
Verify email + password. Returns the user_id if valid.
Timing-equalized: when the email is unknown we still run a throwaway Argon2 verify against a fixed dummy hash. Otherwise an attacker can distinguish “known email, wrong password” (takes ~50ms) from “unknown email” (<1ms) and enumerate registered addresses.
Sourcepub fn change_password(
&self,
email: &str,
old_password: &str,
new_password: &str,
) -> Result<(), String>
pub fn change_password( &self, email: &str, old_password: &str, new_password: &str, ) -> Result<(), String>
Change a user’s password.
Sourcepub fn is_registered(&self, email: &str) -> bool
pub fn is_registered(&self, email: &str) -> bool
Check if an email is registered.
Trait Implementations§
Source§impl Plugin for PasswordAuthPlugin
impl Plugin for PasswordAuthPlugin
Source§fn on_init(&self, _ctx: &PluginContext)
fn on_init(&self, _ctx: &PluginContext)
Called once when the plugin is registered.
Source§fn routes(&self) -> Vec<PluginRoute>
fn routes(&self) -> Vec<PluginRoute>
Custom API routes this plugin handles.
Source§fn before_insert(
&self,
_entity: &str,
_data: &mut Value,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_insert( &self, _entity: &str, _data: &mut Value, _auth: &AuthContext, ) -> Result<(), PluginError>
Called before an entity insert. Return Err to reject.
Source§fn after_insert(
&self,
_entity: &str,
_id: &str,
_data: &Value,
_auth: &AuthContext,
)
fn after_insert( &self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext, )
Called after a successful insert.
Source§fn before_update(
&self,
_entity: &str,
_id: &str,
_data: &mut Value,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_update( &self, _entity: &str, _id: &str, _data: &mut Value, _auth: &AuthContext, ) -> Result<(), PluginError>
Called before an entity update. Return Err to reject.
Source§fn after_update(
&self,
_entity: &str,
_id: &str,
_data: &Value,
_auth: &AuthContext,
)
fn after_update( &self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext, )
Called after a successful update.
Source§fn before_delete(
&self,
_entity: &str,
_id: &str,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_delete( &self, _entity: &str, _id: &str, _auth: &AuthContext, ) -> Result<(), PluginError>
Called before an entity delete. Return Err to reject.
Source§fn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext)
fn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext)
Called after a successful delete.
Source§fn on_request(
&self,
_method: &str,
_path: &str,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn on_request( &self, _method: &str, _path: &str, _auth: &AuthContext, ) -> Result<(), PluginError>
Called on every incoming request (middleware).
Source§fn on_request_with_meta(
&self,
method: &str,
path: &str,
auth: &AuthContext,
_meta: &RequestMeta<'_>,
) -> Result<(), PluginError>
fn on_request_with_meta( &self, method: &str, path: &str, auth: &AuthContext, _meta: &RequestMeta<'_>, ) -> Result<(), PluginError>
Richer variant of [
on_request] that also receives per-request
metadata (peer IP today; more fields may be added later). The
default implementation delegates to on_request so existing
plugins keep working without changes. Plugins that care about
IP — notably rate limiting — override this hook.Source§fn on_session_create(&self, _user_id: &str, _token: &str)
fn on_session_create(&self, _user_id: &str, _token: &str)
Called when a new session is created.
Source§fn entities(&self) -> Vec<ManifestEntity>
fn entities(&self) -> Vec<ManifestEntity>
Additional manifest entities this plugin contributes.
Auto Trait Implementations§
impl !Freeze for PasswordAuthPlugin
impl RefUnwindSafe for PasswordAuthPlugin
impl Send for PasswordAuthPlugin
impl Sync for PasswordAuthPlugin
impl Unpin for PasswordAuthPlugin
impl UnsafeUnpin for PasswordAuthPlugin
impl UnwindSafe for PasswordAuthPlugin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more