1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.gui.dialog;
35
36 import info.magnolia.cms.gui.control.ControlImpl;
37 import info.magnolia.cms.gui.control.Password;
38 import info.magnolia.cms.gui.misc.CssConstants;
39
40 import java.io.IOException;
41 import java.io.Writer;
42
43 import org.apache.commons.lang.StringUtils;
44
45
46
47
48
49
50 public class DialogPassword extends DialogBox {
51
52 private boolean useBcrypt;
53
54
55
56
57 @Override
58 public void drawHtml(Writer out) throws IOException {
59 Password control = new Password(this.getName(), this.getValue());
60 if (this.getConfigValue("saveInfo").equals("false")) {
61 control.setSaveInfo(false);
62 }
63 control.setCssClass(CssConstants.CSSCLASS_EDIT);
64 control.setCssStyles("width", this.getConfigValue("width", "100%"));
65 if (useBcrypt) {
66 control.setEncoding(ControlImpl.ENCRYPTION_HASH_BCRYPT);
67 } else {
68 control.setEncoding(ControlImpl.ENCRYPTION_NO_ENCODING_BASE64);
69 }
70 if (this.getConfigValue("onchange", null) != null) {
71 control.setEvent("onchange", this.getConfigValue("onchange"));
72 }
73 this.drawHtmlPre(out);
74 out.write(control.getHtml());
75 if (this.getConfigValue("verification", "true").equals("true")) {
76 Password control2 = new Password(this.getName() + "_verification", StringUtils.EMPTY);
77 control2.setSaveInfo(false);
78 control2.setCssClass(CssConstants.CSSCLASS_EDIT);
79 control2.setCssStyles("width", this.getConfigValue("width", "100%"));
80 control2.setEvent("onchange", "mgnlDialogPasswordVerify('" + this.getName() + "')");
81 out.write("<div class=\"" + CssConstants.CSSCLASS_DESCRIPTION + "\">" + getMessage("dialog.password.verify") + "</div>");
82 out.write(control2.getHtml());
83 }
84 this.drawHtmlPost(out);
85 }
86
87 @Override
88 public boolean validate() {
89 if (super.getConfigValue("verification", "true").equals("true")) {
90 String newP = super.getRequest().getParameter(getName());
91 String verP = super.getRequest().getParameter(getName() + "_verification");
92
93
94 if (!(newP.trim().length() == 0 && verP.length() == 0) && !newP.equals(verP)) {
95 setValidationMessage(getMessage("dialog.password.failed.js"));
96 return false;
97 }
98 }
99 return super.validate();
100 }
101
102 public boolean isBcrypt() {
103 return useBcrypt;
104 }
105
106 public void setBcrypt(boolean useBcrypt) {
107 this.useBcrypt = useBcrypt;
108 }
109
110 }