Greg On Dynamics Ax

Random thoughts about development using Dynamics AX and .Net

Storing passwords using AX

with one comment

If you need to store passwords in AX there are some application objects, classes and attributes that you can use.  This post details the steps you can take to allow entry of a password in a form, which will be stored in the database.

Password form

1.  Add the password field to your table. This field should be of type ‘CryptoBlob’ which is a container that contains binary data:

Password table field

2. Add an edit method for the password to your table:

//BP Deviation Documented
edit Password editPassword(boolean _set = false, Password _pwd = '')
{
    CryptoBlob cryptoBlob = connull();
    ;

    if (_set)
    {
        this.Password = WinapiServer::cryptProtectData(str2cryptoblob(_pwd));
    }

    return (this.Password == connull()) ? '' : 'xxxxxxxx';
}

3. Drag and drop the edit method to your form and ensure that the attribute ‘PasswordStyle’ is set to ‘Yes’:

Password form control

4. To retrieve the password you will need a method similar to the following:

static Password getPassword(UserId _userId)
{
    CryptoBlob cryptoBlob = TutorialPasswordTable::find(_userId).Password;
    ;

    return (cryptoBlob == connull()) ? '' :
                cryptoblob2str(WinapiServer::cryptUnProtectData(cryptoBlob));
}

 
Disclaimer / Notice / Yada Yada
The safest way to handle passwords is not to store them in the database. The steps described in this post are better than storing the password in the database as plain text, but far from bulletproof. Please ensure that AX security is fully considered if using this method (Table level security, access to code / development etc)

You can download the tutorial as an xpo here from axaptapedia

About these ads

Written by gregondax

May 21, 2009 at 12:30 pm

One Response

Subscribe to comments with RSS.

  1. An example of standard password storing functionality using can also be found in SysEmailParameters table and form. It uses the same principle. (MS DAX 4.x)

    Evgeny

    May 22, 2009 at 5:36 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: