5 Kasım 2013 Salı

AXAPTA - Password field with tables

I followed up Greg on Dynamics AX blog when creating this page.

Firstly we have to add a container field at our table and change it's extended data type as CryptoBlob .

Edit method for our password field:

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


Method get password with X++ code:
Password getPassword()
{
    CryptoBlob cryptoBlob;
    ;
    cryptoBlob = this.Password;
    return (cryptoBlob == connull()) ? '' :
        cryptoblob2str(WinapiServer::cryptUnProtectData(cryptoBlob));
}


Method set password with X++ code:

void setPassword(Password _pwd = '')
{
    CryptoBlob cryptoBlob = connull();
    ;
    this.Password = WinapiServer::cryptProtectData(str2cryptoblob(_pwd));
}

Dot't forget PasswordStyle set to Yes of our form control.

Hiç yorum yok:

Yorum Gönder