Robot Controlled By Human Brain Cells

Today in a moment of spare time when you pass around yours rss to see what’s coming I found this article. The interesting thing wasn’t for me the control per se but the curious coincidence of the natural connections of the neurons and the silicon chip. Maybe it will come the time when the biological and sociological evolution will be in direct interaction with our technology innovation and… evolution?

References:

http://hardware.slashdot.org/article.pl?sid=09/10/20/1236208

Advertisements

I have to learn XSLT AGAIN

Do you remember when someone ask you about some technology, language or something else and your eyes start trying to reach the sky and you start blabbing trying to find anything in your head and nothing comes to you? Well today was my lucky day, some friend ask me about some trouble with XSLT and I couldn’t even remember the most simple things. I remember those days when was the SOA big bang and you HAVE to know all about XML, DTD, XSLT, and so on. Today that bubble was gone and with it much of the knowledge.

Authentication with Active Directory from Forms Authentication

Español

There are two ways that .Net can use to do Active Directory Authentication and this are:

To make a “bind” to Active Directory using LDAP.
To use the Win32 Logon API.

If .Net 3.5 is available you can authenticate with this method:

private bool ValidateExternalUser(string username, string password)
{
    using(PrincipalContext context = new PrincipalContext(ContextType.Domain, _defaultDomain))
    {
          return context.ValidateCredentials(username, password, ContextOptions.Negociate);
    }
}

Before .Net 3.5 you can just bind with your own object:

public bool AuthenticateActiveDirectory(string Domain, string UserName, string Password)
{
    try
    {
          DirectoryEntry entry = new DirectoryEntry(”LDAP://” + Domain, UserName, Password);
          object nativeObject = entry.NativeObject;
        return true;
    }
    catch (DirectoryServicesCOMException) { return false; }
}

Using Win32 Logon API:

It’s very large and fortunately already documented here:
http://www.pinvoke.net/default.aspx/advapi32/LogonUser.html

Another method that we can use when the authentication has to consider Active Directory or SAM local accounts is the following:

[SecurityCritical, DirectoryServicesPermission(SecurityAction.Assert, Unrestricted=true)]
public bool Validate(string userName, string password, ContextOptions connectionMethod)
{
    if ((userName != null) && (userName.Length == 0))
    {
        return false;
    }
    if ((this.contextType == ContextType.Domain) || (this.contextType == ContextType.ApplicationDirectory))
    {
        try
        {
            NetworkCredential creds = new NetworkCredential(userName, password);
            this.BindLdap(creds, connectionMethod);
            return true;
        }
        catch (LdapException exception)
        {
            if (exception.ErrorCode != ExceptionHelper.ERROR_LOGON_FAILURE)
            {
                throw;
            }
            return false;
        }
    }
    return this.BindSam(this.serverName, userName, password);
}

Final Conclusions:

The Win32 Logon API method may be is more verbose of all but has more capabilities like inform the reason behind a failed authentication like account expiration, or if the password has not been set, etc. If you don’t need this advanced behavior it’s recommended the 3.5 or just bind approach.

References:

http://stackoverflow.com/questions/290548/c-validate-a-username-and-password-against-active-directory
http://stackoverflow.com/questions/30861/authenticating-domain-users-with-system-directoryservices
http://archive.devx.com/security/articles/ps0602/ps0602-4.asp
http://support.microsoft.com/kb/316748/en-us
http://msdn.microsoft.com/en-us/library/ms180890(VS.80).aspx
http://www.adventuresindevelopment.com/2009/06/02/how-to-authenticate-a-user-in-active-directory-using-aspnet/
http://support.microsoft.com/kb/180548/en-us
http://www.pinvoke.net/default.aspx/advapi32/LogonUser.html

Unto This Last

Today as you may know it’s the Gandhi anniversary (Ok yes I really remember that thanks to Google and his current Gandhi Theme). I don’t have anything intelligent to write about but if you have some time I really recommend Unto This Last it’s a short book but very good and as I know it was one of the sources of Gandhi inspiration.

http://books.google.com/books?id=pgQGAAAAQAAJ&dq=Unto+The+Last&printsec=frontcover&source=bn&hl=es&ei=ICXGSpioCs-YlAfP2pGSAw&sa=X&oi=book_result&ct=result&resnum=4#v=onepage&q=&f=false