[Kentico 8] How to allow e-mail and username authentication at the same time

Victor Hugo Garcia asked on May 9, 2014 08:22

Hello friends,

I'm implementing a login system for a website and it is required for kentico users to login using their username or email.

on Kentico 7, I saw there is a process to modify some files and allow that, but on Kentico 8, I'm wondering if that is already built-in and so I just have to enable a feature or setting on the system.

Any ideas for Kentico 8?

Thanks in advance

Recent Answers


Victor Hugo Garcia answered on May 12, 2014 11:31

Anybody?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 13, 2014 07:30

You'd have to create a webpart to do that as I don't believe there is one already. Simply take the login webpart and clone it and make the modification to capture the email and verify it.

0 votesVote for this answer Mark as a Correct answer

Victor Hugo Garcia answered on May 13, 2014 16:27

Thanks for the reply, I followed your suggestion that I had to do this manually and I ended adding the validations on global.asax file and also some Membership Providers using the new API and finally making some overrides to some methods in order to acomplish this.

if anybody is interested I left the code below, so you can take it as reference:

MembershipProvider.cs public class MembershipProvider : CMSMembershipProvider { public override bool ValidateUser(string username, string password) { if (ValidationHelper.IsEmail(username)) { string customUsername = base.GetUserNameByEmail(username);

                if (!string.IsNullOrEmpty(customUsername))
                    username = customUsername;
            }

            return base.ValidateUser(username, password);
        }
    }

UserInfoProvider.cs public class UserInfoProvider : CMS.Membership.UserInfoProvider { protected override UserInfo GetUserInfoInternal(string userName) { if (ValidationHelper.IsEmail(userName)) { CMSMembershipProvider membershipProvider = new CMSMembershipProvider(); string customUserName = membershipProvider.GetUserNameByEmail(userName);

                if (!string.IsNullOrEmpty(customUserName))
                    userName = customUserName;
            }

            return base.GetUserInfoInternal(userName);
        }
    }
0 votesVote for this answer Mark as a Correct answer

Martin Danko answered on May 21, 2014 06:56

Hello Victor,

Let me also point out the following KB article: How to allow e-mail and username authentication at the same time

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

Saurav Kumar answered on August 8, 2016 10:04 (last edited on November 28, 2017 14:23)

Hi Victor/Brandon,

I am unable to find CMSAppBase.cs as my kentico version is 9.0.6.
Also my GetUserInfoInternal method isn't being hit and after authentication by email it redirects me back to the login page. It works fine for just username.
Please help!

Edit - I later found out the solution for Kentico 9.0.6 which is listed here

Regards,
Saurav

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.