Remove users with Duplicate Email in ASP.NET membership provider - c#

I'm looking for the most efficient way to remove users with duplicate emails in my asp.net MVC2 website that is using the default membership provider.
We launched this site and did not set unique emails to true, now that I am trying to implement a Forgot Username/Password feature I've come to realize over 100 users have re-registered as they forgot their password and there was no forgot password feature. This is a problem as I need to have the user enter their email to send them their username and password reset email. This fails since multiple users share an email.
I wish I had noticed the unique email option in the web.config before launch, would have saved a huge hassle. :(
I would like to delete all these accounts easily without having to do it manually 1 by 1, and I will then contact them and let them know their duplicate account has been created.
Whats the best way to go about doing this? Some users have registered with the same email up to 5 times.

You could call Membership.GetAllUsers() to get a list of all users.
Then group by MembershipUser.Email, decide which one to keep (for example, keep the account with the most recent LastActivityDate), and delete the others (Membership.DeleteUser).
It would be trivial to write a small program to do all this. Of course you might want to consider whether you should consult your users before deleting their account. E.g. you could send an email telling them that the account will be automatically deleted if they don't reply within some period.

Related

What is a decent way to prevent a malicious user from guessing the UserID of another User using ASP.NET, Entity Framework & SQL Server?

I'm looking for a way to make it difficult for a malicious logged in User to guess the User ID of another user to try and get/change information for another user.
Currently I've got IdentityUsers that each have a NormalUser with more information attached. To create/edit/delete users you'll often see [url]/[action]/[NormalUserID] in the Address bar. Currently the UserID is an automatically incrementing integer and i'm contemplating of changing it to a GUID.
Of course i check whether or not the user has rights to change or view this person (via roles) but it is possible to have users on the same roles so those kind of need to be checked manually. I think this would at least slow down any kind of automated guessing on the malicious user part.
Are there better ways to do it? Is there already something that can help me out with this?
Checking user permissions is the best thing to do anyway. If you wish additionally to prevent potential hacker from guessing user ID of other users, you may use GUID as your user ID.

ASP.Net MVC Identity Forgotten Password

I have setup a quick page to accept an email address which will send an email to it which will later contain a link to reset password or a new temporary one.
My project is a new ASP .Net MVC project using Identity. I thought the best way to reset it would be to send a link to the email which when clicked allows the user to enter a new one but then I'm not sure what to put on the page the link is directed to, to allow this functionality and keep the site secure.
Is it simply easiest in this case to send a new temporary one?
This was too long to fit in a comment so hopefully I don't get downvoted without actual code examples :O
A common solution that I've seen:
When a user requests a password reset, record a guid/random hash and expiration datetime to the user's information in your user store (db most likely).
An email with a link to a temporary page is sent to the user's email address on file (this solution does require a valid email address).
Once the temporary page is hit, the link can be set to immediately expire (set the expiration date to datetime.now, or remove the guid/hash from the user info, etc).
This temporary page URL would likely have the guid/hash for the recorded user in the query string, so it should be pretty hard to find without having the link in the email. For added security, the user can be required to put in the username/email that requested the password reset (as there should potentially be no mention of usernames/passwords on the page. Once this validation is done (or not) give the user the appropriate fields to reset their password.
Another final note on the "forgot password link" don't provide any information on whether or not a username "does not exist" as this can give the potential of finding valid user names on your site.
EDIT:
here's a previous stack overflow question that might explain it better than I did (don't look at the "accepted" answer, look at the most upvoted answer. :)
Generate temporary URL to reset password
You can find a complete sample that uses "Forgot password" functionality in the prerelease version of "Microsoft ASP.NET Identity Samples 2.1.0-alpha1" NuGet package.
Steps
Create Empty Web Application project
Install sample project: Install-Package Microsoft.AspNet.Identity.Samples -Pre
Start the application and register a new user.
Go to Log in page an click on "Forgot password". Then add the recent registered user e-mail.
Then, you will be able to debug the application checking the "Forgot password" process.

The solution to restore user password by sending the lost password via the registered email address?

I want to add this feature to my application. It works OK but I'm afraid of a problem here. At first, I'll talk a little about how I implement the feature. Simply, the user has to register his email address first (at the registration time). If he loses his password, he can click on a link to activate the sender. This sender will send the password (corresponding to his username) to his registered email address. I think there should have many kinds of sender here and I'm using SmtpClient to send the email. This Smtp needs a NetworkCredential, and I provide it with some valid and active Credential. I have to create some user accounts (in Gmail and Yahoo networks), apply these accounts information as the credentials for my Smtp.
Here is the problem, my Password restoring feature won't work if all those credentials being invalid or inactive. I mean if all the user accounts (I created in Gmail and Yahoo mail) somehow are inactive, the Smtp will be unable to send the email. The most popular reason for those accounts being inactive is there hasn't been any access/login to them for a long time (e.g: about 3 months) It is almost certain that it will happen, except I have to remind myself to login to those accounts periodically to keep them active.
I wonder if there is any solution for this? I've thought of keeping those accounts information in a config file but the customer won't know how to edit that config file to change the sender credential information and even they know how to, that's so inconvenient. I've also thought of popping up a window requiring information for the sender credential from user (user may use his own email account or has to create a new one), it's also inconvenient, I think so. I've also think of logging to those accounts (via my application) periodically (about once a month) to keep them active. But I wonder if there is a better solution, plus that requires the user computer to be connected to Internet and this is not always met (even there is a situation that the user computer is always off line for months or years, but suddenly one day, he loses his password, he wants to get it back and at that time, he connects his computer to the Internet and uses the password restoring feature, but he can't because all the accounts built-in for the sender credentials has been inactive because of not having any access/login to them for months/years).
Do you have any idea on how to solve this problem?
UPDATE
I'm sorry to who suggested me that there is a security flaw here but I just want a solution for the password restoration. If you are kind enough please let me know what the security flaw is in detail. As I mentioned above, there is of course a security flaw because of the user password (a plain text) is saved in memory. But that's just a demo and it's only for demonstrative purpose for my real problem which is sending the user a new password (or any kind of authoritative access info). Here is what I want to explain more:
Suppose user's password is: Iloveprogramming
After hashed, it should be 3920bdbd4c000dd392e2501e89747173
That's all my application knows about user's access info.
When user typed in his password correctly, that entered password should be hashed into the same string above and this will be compared against the hashed string stored in the database and he should be logged in.
Now if he forgets his password, What can I do?
Here is the way most of websites do for us (who unfortunately forget our passwords):
- Support a link like "Forgot your password?"
- Clicking the link will lead you to a page like this:
-> Supply your user name: ............
-> Click OK (or any submit button) to get your new password.
I would like to do the same with my application. This is a windows forms application. I know that the content sent to the user email address should only be some confirmation link (about the password restoration), not a password (this is known only by the user who uses the email the password is sent to, however other users may disturb him by clicking on the 'Forgot password' link and fill in his user name). But it is only a must-do for a multi-user application, my application is in fact for only 1 user using on his own machine. What is the flaw?
Here is what I intend to do:
Auto-Generates the password, hashes this password and saves that hashed string into the database as the new hashed password for him. After that, send this auto-generated password immediately to his email address.
Dispose the string which stores the newly generated password.
What is the flaw here? And if it does exist, please let me know another solution for this? I'm just afraid of the email account which is used to send the password to my user's email address may not work (inactive) in future for some reason (as I said, not logging in for a long time).
Please feel free to explain the flaw detail in an answer, it may not answer to my original question but it does help me and I would accept that answer. Thank you!
Again, I don't have money for a dedicated website for the password restoring feature of my winforms application.

how can my application remember username and password after the user logs in?

When the user check "remember me" i want to save the username and password.
The user should be able to login directly the next time.
What is the best way to do this?
I tried isolated storage but maybe the code i wrote is incorrect.
I hope someone can help me.
There is a great how-to on how to Encrypt Data in a Windows Phone Application - it may be worth comparing that code with yours
The best and secure way to do this.. Is storing unique ID which are relevant only to the servers that you are talking to as cookies.
Algo:
Get the username and password from the user
Check for authenticity of the user.
If authenticated, then generate an unique ID relevant to this user and store it on server.
Pass on this unique ID to client side and store this in a cookie. Set the max-age
Next time when the user come to your site. Check for the unique ID on the server and also check its age as well as when it was issued
If all's well , then give access to user

ASP.Net Membership Password recovery

Current state of Application
We got a huge user base currently and we had requiresUniqueEmail="false" setting from day one bcse business required such.
So our password recovery was done via UserName.
Issue/Problem
Suddenly the business wants the password recovery to be done either by Username or Email. But bcse we never had unique emails in the system (in few cases no email), we are having quite a few duplicate emails in the system. For example, xyz#xyz.com is assigned to 10 different usernames.
How can I tackle this situation in best possible way?
I was thinking along the lines, if a user selects by email, I will go ahead and send all the usernames which are associated with this email. Is that a good option?
Would love to have more ideas on this. I am sure someone should have had this sort of issue before.
When accounts were set up did it send out a validation email to ensure people only subscribed using email addresses they owned? If so then you could send out all username's safe in the knowledge the owner of the email created them. If you didn't require validation then possibly anyone could get the email and read someone else's account.
You can use email to narrow down to a single username recovery. For example:
Given a set of 10 usernames with the same email "email#domain.com"
When I click "Recover Password By Email"
And I enter "email#domain.com"
Then I should see the message "select which username you want to recover"
And I should see a list of the 10 usernames
When I click on the username "username1"
Then I should receive a password recovery email for the "username1" account
at the "email#domain.com" address
This way, you're still doing recovery by username, but only when the email has more than 1 username match.
I don't like the idea of sending the password recovery to all usernames. The user may have only forgotten one password.

Categories

Resources