Last post Jul 15, 2014 05:38 AM by Mikesdotnetting
Jul 14, 2014 04:47 AM|Chris17|LINK
I started this thread on changing password: http://forums.asp.net/t/1995808.aspx?Use+WebSecurity+PasswordReset+without+the+mail+service but thins refused
to work out for me.
I dont know if i can actually update the table bearing the database directly without having to use the websecurity herlper.
Jul 14, 2014 05:02 AM|AidyF|LINK
It is simple if the password storage system is plain text. If it isn't you'll need to hash the password and salt correctly yourself. If the problem is that you can't get the membership api working then you should fix whatever that problem is. Look at
the following for how you can reset someone's password
It also has code for how you set a password to a specific bit of text if you scroll to the bit that starts "One workaround is to first reset the user's password and then change it to the new password using code like the following"
You can also do it by calling the in-buiolt sp directly
Jul 14, 2014 10:12 PM|Starain chen - MSFT|LINK
AidyF’s reply is good.
For your previous thread:
First, to get current user’s name, we could use this code below:
Secondly, I think the change password function is used for current user. If you let to type his user name, then he can change others password.
To conclude, for change password function, you need to verify current user is authenticated, for example:
if (IsPost && Validation.IsValid()&&WebSecurity.IsAuthenticated)
Jul 15, 2014 02:36 AM|Mikesdotnetting|LINK
You can just use the Crypto helper's HashPassword function to generate a hash of a password and insert the result in the database. http://msdn.microsoft.com/en-us/library/system.web.helpers.crypto.hashpassword(v=vs.111).aspx
It's the method that is used by the WebSecurity helper internally.
Jul 15, 2014 04:48 AM|Chris17|LINK
Thanks Aidy, Starain and Mike.
If I should go by Mike's option, can you help me with an example of HashPassword().
Jul 15, 2014 05:07 AM|Chris17|LINK
Ok! Now I did something like this:
db.Execute("insert into webpages_Membership (Password, UserId, PasswordChangedDate) values @0, @1, @2", Crypto.HashPassword(password), WebSecurity.CurrentUserId, DateTime.Now);
and I get this error:
There was an error parsing the query. [ Token line number = 1,Token line offset = 80,Token in error = @0 ]
Jul 15, 2014 05:38 AM|Mikesdotnetting|LINK
db.Execute("insert into webpages_Membership (Password, UserId, PasswordChangedDate) values (@0, @1, GetDate())", Crypto.HashPassword(password), WebSecurity.CurrentUserId);