.Net ramblings
# Tuesday, 23 January 2007
HowTo: Correct Login Username Case
using Forms auth in an asp.net web site, with a standard Login control, i found a problem today where user 'Joe Bloggs' can log in with 'JOE BLOGGS' as his username.  this messes up my database a little because User.Identity.Name yields 'JOE BLOGGS' and i use this value in the application database. for consistency purposes i only want to use the case-correct version of the username, as it was created.

to fix this, i added the following code to my login
    protected void Login1_LoggedIn(object sender, EventArgs e)
        // correct the case of the username
        foreach(MembershipUser u in Membership.GetAllUsers())
            if(u.UserName.ToLower() == this.Login1.UserName.ToLower())
                // fix the username case
                FormsAuthentication.SetAuthCookie(u.UserName, true);

Tuesday, 23 January 2007 15:05:27 (GMT Standard Time, UTC+00:00)  #    Comments [4]  Asp.Net