To be able to inform a user about it's newly created account, and provide the users it's password I thought of the following construction, which sets a new password which I afterwards send by e-mail. However.. one problem! The password never gets updated.. it stays the initally password set by the umbraco dialog.
I use this code:
Member.New += new Member.NewEventHandler(Member_AfterNew);
You shouldn't need to encode the password yourself, as this is built into the Member entity whenever you use the Password field setter (it auto looks up the configuraed hash method for the Member MembershipProvider).
I think the only thing you need to do extra (as shown in Saschas post) is to call
member.save()
After you rest the password. You may also want to store the member.ResetPassword() in a variable before passing it to the ChangePassword method so that you can add it to your email.
You're right that accessing the Member class is depeceiated, but I tend to find if you are doing anything more complex than simply creating a user, or authenticating a user, there isn't really a way round it. If you actually look at the membership providers, you'll see it actually uses the Member classes anyway, and I wouldn't imagin that these are going to be dropped before v5, so it should be pretty safe to use.
Reset password after creating new user
To be able to inform a user about it's newly created account, and provide the users it's password I thought of the following construction, which sets a new password which I afterwards send by e-mail. However.. one problem! The password never gets updated.. it stays the initally password set by the umbraco dialog.
I use this code:
Member.New += new Member.NewEventHandler(Member_AfterNew);
void Member_AfterNew(Member sender, NewEventArgs e)
{
String userName = sender.LoginName;
String newPassword = Membership.GeneratePassword(7,2);
MembershipUser user = Membership.GetUser(userName);
user.ChangePassword(user.ResetPassword(), newPassword);
// ... send by email the newPassword
}
What could possibly go wrong?
AFAIK you need to manually encode the password before saving it (if you are storing the passwords as hashes), like so:
Don't know if that is your problem here though, but thought I'd mention it anyways. :)
I have so far only used the depracated Member object to perform these operations, e.g.
, which seems to do the trick.
Hey,
You shouldn't need to encode the password yourself, as this is built into the Member entity whenever you use the Password field setter (it auto looks up the configuraed hash method for the Member MembershipProvider).
I think the only thing you need to do extra (as shown in Saschas post) is to call
After you rest the password. You may also want to store the member.ResetPassword() in a variable before passing it to the ChangePassword method so that you can add it to your email.
Many thanks
Matt
Thanks for your replies guys! However none of them solves my problem.
I used the example from this page: http://our.umbraco.org/wiki/how-tos/membership-providers
Related config info:
<add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed" />
Anyone?
Hey,
You're right that accessing the Member class is depeceiated, but I tend to find if you are doing anything more complex than simply creating a user, or authenticating a user, there isn't really a way round it. If you actually look at the membership providers, you'll see it actually uses the Member classes anyway, and I wouldn't imagin that these are going to be dropped before v5, so it should be pretty safe to use.
Matt
is working on a reply...