0

I am facing a very strange issue in Sitecore 8.1 update2 instance. There is a field of Password type. Though in content Editor its value appears in dots format but on clicking Version-> Compare button,the password field actual value gets exposed( refer screenshot). I checked all dlls and config files but found nothing. Then I replaced my master database connectionstring in a Vanilla instance, then issue reproduced in Vanilla instance as well.. Which means some setting has changed in master database but I could not figure out yet what setting is causing issue.

Please let me know if someone has face similar issue or how can I fix this issue.

enter image description here

  • 2
    That's just how it works. If you inspect the markup you'll see that is a div rather than a textbox. The version diff dialog makes no special provision for passwords, you would need to amend it to hide passwords. There probably isn't much point to that as you can see the password anyway via View->Raw values. – Aidy Dec 18 '19 at 10:35
  • Yes you are right, I verified in fresh instance and it shows text. Thanks for replying. – arun tiwari Dec 18 '19 at 13:52
3

Aidy's statement is 100% correct with the Sitecore version you are using but with the Sitecore version 9, the Password field is changed a little bit and works as per your requirement and not expose the value event via Raw values. If you want the same functionality in Sitecore version 8.1u2 then you need to customize the existing password field or need to create a new password field. I am sharing updates for existing password field here-

  • Create a new class field, give it the same name as the field name. i.e Password
  • Add the below code -

      public class Password : Sitecore.Shell.Applications.ContentEditor.Text
     {
        public Password()
         {
        this.Password = true;
        this.Activation = true;
         }
    
    protected override bool LoadPostData(string value)
    {
        value = StringUtil.GetString(value);
        if (this.Value == value || this.Value.Replace("\n", string.Empty) == value || this.Value.Replace(Environment.NewLine, string.Empty) == value)
            return false;
        this.Value = value;
        this.SetModified();
        return true;
    }
    
    protected override void SetModified()
    {
        base.SetModified();
        if (!this.TrackModified)
            return;
        Sitecore.Context.ClientPage.Modified = true;
    }
    
    protected override void DoRender(HtmlTextWriter output)
    {
        this.Attributes["placeholder"] = Translate.Text(this.Placeholder);
        this.SetWidthAndHeightStyle();
        string str = this.TransformPasswordText();
        output.Write("<input" + this.ControlAttributes + str + ">");
        this.RenderChildren(output);
    }
    
    
    private string TransformPasswordText()
    {
        string str = string.Empty;
        if (this.Password)
        {
            str = " type=\"password\"";
            try
            {
                this.Attributes["value"] = new StringBuilder().Insert(0, "•", this.Attributes["value"] == null ? 0 : this.Attributes["value"].Length).ToString();
            }
            catch
            {
                Log.Warn("Could not resolve password length.", (object)this);
            }
        }
        if (!string.IsNullOrEmpty(str))
            return str;
        return !this.Hidden ? "" : " type=\"hidden\"";
    }
     }
    
  • After that next step is to add a patch config for our custom course, where you need to pass namespace where your Password class is located, assembly name and a prefix to identify the control source -

    <configuration xmlns:x="https://www.sitecore.com/xmlconfig/">
      <sitecore>
        <controlSources>
          <source mode="on" namespace="yournamespace" assembly="yourassemblyname" prefix="customcontent" />
        </controlSources>
         </sitecore>
        </configuration>
    
  • The next step is to update the Password field in the core database. Navigate to password field - /sitecore/system/Field types/Simple Types/Password and update the control field with the prefix and class name (prefix:classname), in our case it will be customcontent:password -

enter image description here

In the above code, TransformPasswordText function is taking care for transforming the password text into ***.

I think this will resolve your problem. If you want to create a separate field then you can simply duplicate the existing password field and perform the same steps.

| improve this answer | |
  • Thanks a lot. Its helpful. – arun tiwari Dec 18 '19 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.