Me User
Me User

Reputation: 39

How do I trigger a reset password?

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    
  1. The problem is how do I get the ??? - the new automatic password I created by the method: user.ResetPassword();
  2. Can I define the TRIGGER to be used only with user.ResetPassword(), and not with other methods (like: (user.ChangePassword(...))?
  3. Maybe there is another simple way to trigger reset password?

Thank you.

Upvotes: 2

Views: 507

Answers (1)

codingbiz
codingbiz

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

Related Questions