0

What is best practice for extending C1 logon functionality. Would like to extend features to the current logon process by replacing password authentication with multifactor authentication. I am interested in knowing the key concepts and hooks into C1 to permit user authentication into C1 after completing the multifactor authentication.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Kevin
  • 45
  • 4

1 Answers1

0

Have you looked at this discussion http://compositec1.codeplex.com/discussions/268428 ? Here there is sample-code for class implementing the ILoginProvider interface, that gets called when authenticating a username/password combination.

public class LDAPLoginProvider : IFormLoginProvider
{
    public bool CanSetUserPassword
    {
            get { return false; }
    }

    public bool CanAddNewUser
    {
            get { return false; }


    public bool UsersExists
    {
            get { return DataFacade.GetData<IUser>().Any(); }
    }

    public IEnumerable<string> AllUsernames
    {
        get { return (from u in DataFacade.GetData<IUser>() select u.Username).ToList(); }
    }

    void SetUserPassword(string username, string password) 
    {
        throw new NotImplementedException();
    }

    void AddNewUser(string userName, string password, string group) 
    {
        throw new NotImplementedException(); 
    }

     LoginResult Validate(string username, string password)
     {
        var user =
            (from u in DataFacade.GetData<IUser>()
             where String.Compare(u.Username, username, StringComparison.InvariantCultureIgnoreCase) == 0
             select u).FirstOrDefault();

        if (user == null)
        {
            return LoginResult.UserDoesNotExist;
        }

        bool loginIsValid = false;

        try
        {
            var entry = new DirectoryEntry("LDAP://domain.com", username, password);
            object nativeObject = entry.NativeObject;
            loginIsValid = true;
        }
        catch (DirectoryServicesCOMException ex)
        {
            //not authenticated; reason why is in ex
        }
        catch (Exception ex)
        {
            //not authenticated due to some other exception
        }

        return loginIsValid ? LoginResult.Success : LoginResult.IncorrectPassword;
    }         
}

Here users still needs to be created in C1, but the passwords are validated against an external source, here a LDAP server.

Pauli Østerø
  • 6,878
  • 2
  • 31
  • 48