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

Created 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("Failed to save the password. Please try again");
            }
            else
            {
                warning("Failed to read the password. Please clear and re-enter the password.");
            }
        }

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

To decrypt stored password you can use same passwordEdit method:
Info(parameters.passwordEdit(false, ''));
Password EDT allows 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.
Join us.

Blog Tags