Search This Blog

Wednesday, June 17, 2015

Masking control in CRM 2015

Password Masking in CRM 2015

If you have any doubt in the post please post comments. I will try to solve your problem.

In CRM there is no default password masking, we have to manually write a java-script code to achieve it.

We have to mask Password and some other control based on our requirement. Here i was masked password and license key.
Solution:
There are two ways to achieve it.
a) we can give field level security
b) Using javascript we can hide.

Field Level Security
If you give field level security, We have to give all roles create rights and disable edit rights.but system administrator can view this field any time.

Javascript
Even system administrator also not able to see in edit mode. We have full control on our code.

1) Create new column as password masking(new_passwordmasked).
2) Place the column in the CRM form
3) Write a "OnSave" event code in the form.
     Get the value from password control and masked that value and save it in another control.

  var Password = Xrm.Page.getAttribute("new_password").getValue();
       if(Password != null){
                  Xrm.Page.getAttribute("new_passwordmasked").setValue(Password.replace(/.+/, "************"));
        }
  Using regex we masked the password control
4) Write "onLoad" event in form to enable and disable the password and masked password control.


   if (Xrm.Page.ui.getFormType() == 1) {
       Xrm.Page.getControl("new_password").setVisible(true);
       Xrm.Page.getControl("new_passwordmasked").setVisible(false);
   } else {
       Xrm.Page.getControl("new_password").setVisible(false);
       Xrm.Page.getControl("new_passwordmasked").setVisible(true);

   }
Here we are enable and disable the control based on the form type because in new mode we have to show password control and it edit mode we have to show "masked password control".

Why do we need two control?
Because you may use this password control value from another form. In that you need extact value not masked value. That's why we are using two control.

We are not encoded or encrypt the password value,just replace the value as *.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.