We help IT Professionals succeed at work.

VS08 login control - allow user to use email vs. username to login

McGurk1
McGurk1 asked
on
I have a site that uses the login control found in VS08.  However, those I created the site for would like users to have the ability to login using their email address instead of the username.  From researching, I have found that simply requiring the username to be an email can cause issues.  One site I found referenced a 4GuysFromRolla article but that did not fully really address using an email.  Does anyone know how to do this or where I can find some good code examples?
Comment
Watch Question

Top Expert 2011

Commented:
Do your users register to create their own account or do you create it for them?

I know you made a reference to control found in VS08,however, I would create my own custom login table and then create username of varchar or nvarchar.

It wouldn't matter then what the user uses as username.

Infact, you can specifically request that user enters email address as user name.

Then user javascript to ensure proper email address is entered.

Author

Commented:
Users create their own.  Thanks for the suggestion.  At this point, I am not ready to redo it all but will keep it in mind if I cannot resolve this otherwise.
Top Expert 2011
Commented:
Then that's fine, you don't have to.

If users create their own account but now, your client wants users to use email as username.

You can easily fix that by indicating that users enter email address as username.

Then use javascript to ensure that proper email format is followed.

if you need help with that, let me know.

A simple regex will handle that.
<script type="javascript/text">
    function validateEmail() {
        if (document.getElementById('empl_email').value == "") {
            alert("Email address can not be blank");
            document.getElementById('empl_email').focus();
            return false;
        }
        var emailPat = /^\w[\w\-\'\.]+\@(\w[\w\-\']*\.)+[a-z]{2,6}$/;
        var emailid = document.getElementById('empl_email').value;
        var matchArray = emailid.match(emailPat);
        if (matchArray == null) {
            alert("Your email address format seems incorrect. Please try again.");
            document.getElementById('empl_email').focus();
            return false;
        }

Open in new window

       return true;
    }

Author

Commented:
Thanks.  Works great.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.