Reputation: 39
I work in Microsoft .NET 4.0 environment. In my application I enable the user to get new automatic password. So I use in my .cs file the method:
MembershipUser user = Membership.GetUser();
user.ResetPassword();
I want to trigger on reset Password, means: when the password is changed to the automatic one, an email will be sent to the user's email address with the new password (that is returned from user.ResetPassword()).
I use standard Membership DB tables.
I wrote the following trigger:
CREATE TRIGGER MembershipChangePass ON aspnet_Membership
AFTER UPDATE,DELETE
AS
BEGIN
DECLARE @user uniqueidentifier
DECLARE @email nvarchar(256)
SELECT @user = (SELECT UserId FROM UPDATED)
SELECT @email =(SELECT LoweredEmail FROM aspnet_Membership
WHERE @user=UserId)
EXEC xp_sendmail @email, ???
END
GO
Thank you.
Upvotes: 2
Views: 507
Reputation: 26396
The ResetPassword()
method returns the new password which you can grab and send to the user
string newPassword = user.ResetPassword();
string toAddr = "user email here";
string subject = "Password reset notification";
string body = "Your new password is "+newPassword;
//mail.Send(fromAddr, toAddr, subject, body);
Upvotes: 1