How to store encrypted passwords in D365FO

Here is how you can store encrypted passwords in D365FO:

1. Preferably create a new table specifically for this purpose

Create a new field of type container and EDT EncryptedField called "Password"

2. Overwrite update and insert methods of the table:

public void update()
 {
    Global::handleEncryptedTablePreUpdate(this);
    super();
    Global::handleEncryptedTablePostUpdate(this);
 }
public void insert()
 {
    Global::handleEncryptedTablePreInsert(this);
    super();
    Global::handleEncryptedTablePostInsert(this);
 }

3. Add edit method to the table

    public edit Password passwordEdit(boolean _set, Password value)
    {
        System.Exception ex;

        Password password = '';

        try
        {
            password =  Global::editEncryptedField(this, value, fieldNum(VKParameters, Password), _set);
        }
        catch (ex)
        {
            boolean exceptionNested = false;
            while (ex != null)
            {
                exceptionNested = true;
                ex = ex.InnerException;
            }

            if (_set)
            {
                warning(strFmt("Failed to save the '%1'. Please try again.", fieldId2PName(tableNum(VKParameters), fieldNum(VKParameters, Password))));
            }
            else
            {
                warning(strFmt("Failed to read the '%1'. Please clear and re-enter it.", fieldId2PName(tableNum(VKParameters), fieldNum(VKParameters, Password))));
            }
        }

        return password;
    }
4. On the form, change property Password Style = Yes for the password control

To decrypt stored password you can use the same passwordEdit method:
Info(parameters.passwordEdit(false, ''));
Password EDT allows you to store only up to 20 chars, change it if you need more.

Standard example:
  • System administration / Setup / Email / Email parameters / SMTP settings
  • SysEmailParameters form
  • SysEmailSMTPPassword table

 

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units and "buy me a coffee" link.
Join us.

Blog Tags