0

All,

I am working on an MVC3 c# site. I need the ability for a user to request a new password. The requirement is that they enter either:

  • Their customerId if they know if

OR

  • Their chosen username in the one textbox

Both are unique in the database.

Once they enter either of these, a 'change password' link is sent to them in an email.

My question is, I am using one text box for them to enter either of these.

How do I know what one they entered?

Do I validate for a username and if this fails then validate for a customerId. If these both fail validation then I show them a message.

If one of these validates then I send them the password link.

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
RuSs
  • 1,725
  • 1
  • 29
  • 47
  • What if a user has a username that happens to be someone else's customer ID? – Slippery Pete Dec 19 '12 at 22:12
  • When creating a username we will check to see if there is an existing one and make them choose another one. We wont have that many members – RuSs Dec 19 '12 at 22:17
  • Validate for username since ID can't be a string. If username fails, test for ID. To be honest tho, you are just looking for trouble. It would ultimately be better if you have 2 seperate forms. – cen Dec 20 '12 at 04:13

2 Answers2

1

You said you are using a single textbox for both i.e for username and customerId.

This is wrong by design !

What will you do if say Customer A's username happens to be Customer B's customerId ??

What I suggest you have is two textboxes, each properly labelled that one is for customerId and other is for username and the user is required to fill EITHER of the two.

Hope this helps.

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
0

If the ID is a numeric value or follows a particular format then you could use a regex to check for a match and then treat is as an ID or username. Note that if the ID is just a number then it would be more efficient to call TryParse to check the input.

MarkG
  • 1,859
  • 1
  • 19
  • 21