How to Store Passwords Using Dynamics AX

Description: 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.

Step 1: Create Table Name it “A_PasswordTable”. And Insert Filed in Table.
  • Expand AOT Node.
  • Open Data Dictionary Node.
  • Select Tables and right Click Select New Table.
  • Name it “A_PasswordTable”.
  • Now open table in Insert Some Data in A_PasswordTabletable.

Step 2: Now Create Form and Name it “A_PasswordForm”. And Add List box and StringEdit Controls in Design Node.
  • Expand AOT Node.
  • Select Form Node and Right Click Select New Form and Name it “A_PasswordForm”.
  • Now Drag and Drop Table in Form DataSource.
  • Design your Form like below.

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

edit Password editPassword(boolean _set = false, Password _pwd = '')
{
    CryptoBlob cryptoBlob = connull();
    ;
    if (_set)
    {
        this.Password = WinapiServer::cryptProtectData(str2cryptoblob(_pwd));
    }
    return (this.Password == connull()) ? '' : 'xxxxxxxx';
} 

  • Drag and drop the edit method to your form and ensure that the attribute ‘PasswordStyle’ is set to ‘Yes’:
To retrieve the password you will need a method similar to the following:

static Password getPassword(UserId _userId)
{
    CryptoBlob cryptoBlob = A_PasswordTable::find(_userId).Password;
    ;
    return (cryptoBlob == connull()) ? '' :
    cryptoblob2str(WinapiServer::cryptUnProtectData(cryptoBlob));
} 

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.).
For finding Record in table Create find Method in Table.

public static A_PasswordTable find(UserName _userName,boolean  _forUpdate = false)
{
    A_PasswordTable PasswordTable;
    ;
    if (_userName)
    {
        PasswordTable.selectForUpdate(_forUpdate);
        selectfirstonly PasswordTable
        where PasswordTable.UserName == _userName;
    }
    return PasswordTable;
}

For Check Record is Exist in the table or not create exist method in table for check record.

public static boolean exist(UserName _userName)
{
    ;
    return (select RecId from A_PasswordTable where A_PasswordTable.UserName == _userName).RecId != 0;
}

Related Posts

Previous
Next Post »

1 comments:

comments

Thanks for comments.....