Skip to content

Commit f957ce1

Browse files
committed
Passwortanpassungen
#444
1 parent 241645a commit f957ce1

File tree

4 files changed

+170
-144
lines changed

4 files changed

+170
-144
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
Changelog
22
=========
33

4+
Version 4.3.1 - xx.03.2024
5+
6+
### Anpassungen
7+
8+
* Referer to logout greift nur noch, wenn Article Logout vorhanden ist. Danke Julian Aliabadi, https://github.com/goldfoot
9+
* Verlinkung auf Docs angepasst
10+
* rexstan Satisfaction erhöht. Danke https://github.com/TobiasKrais
11+
* Doppelte Registrierung des yform template path entfernt. Danke https://github.com/tyrant88
12+
* Fehler bei Installation behoben. Passwortfeld wurde vorher nur nach Reinstall angelegt.
13+
* Passwort autocomplete varianten eingebaut und in Doku sinnvoll ergänzt
14+
* CSP Header anpassungen. Passwortscript -CSP-fähig und relationsfähig gemacht.
15+
416
Version 4.3.0 - 14.03.2024
517
--------------------------
618

docs/03_login_logout_profile_register.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
```text
99
validate|ycom_auth|login|password|stayfield|warning_message_enterloginpsw|warning_message_login_failed
10-
text|login|Benutzername|
11-
password|password|Passwort
10+
text|login|Benutzername|||{"autocomplete":"username"}
11+
password|password|Passwort|||{"autocomplete":"current-password"}
1212
checkbox|stayfield|eingeloggt bleiben
1313
ycom_auth_returnto|returnTo|
1414
```
@@ -22,8 +22,8 @@ $form->setValidateField('ycom_auth', ['login', 'password', null, 'warning_messag
2222
$form->setObjectparams('form_name', 'login_form');
2323
$form->setObjectparams('form_action', rex_getUrl());
2424

25-
$form->setValueField('text', ['login', 'Benutzername']);
26-
$form->setValueField('password', ['password', 'Passwort']);
25+
$form->setValueField('text', ['login', 'Benutzername', '', '', '{"autocomplete":"username"}']);
26+
$form->setValueField('password', ['password', 'Passwort', '', '', '{"autocomplete":"current-password"}']);
2727

2828
$form->setValidateField('empty', ['login', 'Bitte geben Sie Ihren Benutzernamen ein']);
2929
$form->setValidateField('empty', ['password', 'Bitte geben Sie Ihr Passwort ein']);
@@ -136,7 +136,7 @@ text|name|Nachname*
136136
validate|empty|name|Bitte geben Sie Ihren Nachnamen ein.
137137

138138
ycom_auth_password|password|Ihr Passwort*|{"length":{"min":10},"letter":{"min":1},"lowercase":{"min":0},"uppercase":{"min":0},"digit":{"min":1},"symbol":{"min":0}}|Das Passwort muss mindestens 10 Zeichen lang sein und eine Ziffer enthalten.
139-
password|password_2|Passwort bestätigen*||no_db
139+
password|password_2|Passwort bestätigen*||no_db|{"autocomplete":"new-password"}
140140

141141
checkbox|termsofuse_accepted|Ich habe die Nutzungsbedingungen akzeptiert.|0|0|
142142

docs/05_passwords.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Nun können Nutzer ihr Passwort selbständig ändern.
3535
1. Feld für altes Passwort und Validierung hinzufügen
3636

3737
```php
38-
password|old_password|Bisheriges Passwort||no_db
38+
password|old_password|Bisheriges Passwort||no_db|{"autocomplete":"current-password"}
3939
validate|empty|old_password|Bitte das bisherige Passwort angeben.
4040
validate|ycom_auth_password|old_password|Das bisherige Passwort ist nicht korrekt.
4141
```

plugins/auth/ytemplates/bootstrap/value.ycom_password.tpl.php

Lines changed: 152 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838
'type' => $type,
3939
'id' => $this->getFieldId(),
4040
'value' => $value,
41-
'autocomplete' => 'new-password',
4241
];
4342

43+
if (rex::isFrontend()) {
44+
$attributes['autocomplete'] = 'new-password';
45+
}
46+
4447
$attributes = $this->getAttributeElements($attributes, ['autocomplete', 'pattern', 'required', 'disabled', 'readonly']);
4548

4649
$span = '';
@@ -50,14 +53,23 @@
5053
if ($script) {
5154
$funcName = uniqid('rex_ycom_password_create' . $this->getId());
5255
$span = '<span class="input-group-btn">
53-
<button type="button" class="btn btn-default getNewPass" onclick="' . $funcName . 'refresh(' . $this->getId() . ')"><span class="fa fa-refresh"></span></button>
56+
<button type="button" class="btn btn-default getNewPass rex-ycom-password-refresh-button" data-myRules=\'' . json_encode($rules) . '\' data-myField="' . rex_escape($this->getFieldName()) . '"><span class="fa fa-refresh"></span></button>
5457
</span>';
5558

5659
$nonce = '';
5760
$nonce = ' nonce="' . rex_response::getNonce() . '"';
5861

5962
?><script type="text/javascript"<?= $nonce ?>>
6063

64+
$(document).on('rex:ready', function () {
65+
$(".rex-ycom-password-refresh-button").each(function() {
66+
$(this).off("click");
67+
$(this).on("click", function() {
68+
rex_ycom_password_refresh(this);
69+
});
70+
});
71+
});
72+
6173
// Credit to @Blender https://stackoverflow.com/users/464744/blender
6274
String.prototype.pick = function(min, max) {
6375
var n, chars = '';
@@ -92,153 +104,155 @@
92104
return array.join('');
93105
};
94106

95-
function <?= $funcName . 'refresh' ?>(input) {
96-
97-
var rules = {
98-
letter:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
99-
uppercase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
100-
lowercase: "abcdefghijklmnopqrstuvwxyz",
101-
digit: "0123456789",
102-
symbol: "!@#$%^&*()_+{}:\"<>?\|[];',./`~",
103-
all: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+{}:\"<>?|[];',./`~",
104-
};
105-
rules.letter = rules.uppercase + rules.lowercase;
106-
rules.all = rules.uppercase + rules.lowercase + rules.digit + rules.symbol;
107-
108-
var ruleset = '';
109-
var myRules = <?= json_encode($rules) ?>;
110-
var myPassword = '';
111-
112-
if (typeof myRules.uppercase === "object") {
113-
min = myRules.uppercase.min;
114-
if (typeof myRules.uppercase.min === "undefined") {
115-
min = 1;
116-
}
117-
max = myRules.uppercase.max;
118-
if (typeof myRules.uppercase.max === "undefined") {
119-
max = min;
120-
}
121-
generate = myRules.uppercase.generate;
122-
if (typeof myRules.uppercase.generate !== "undefined") {
123-
min = generate;
124-
max = generate;
125-
}
126-
ruleset += rules.uppercase;
127-
myPassword += rules.uppercase.pick(min,max);
128-
}
129-
if (typeof myRules.lowercase === "object") {
130-
min = myRules.lowercase.min;
131-
if (typeof myRules.lowercase.min === "undefined") {
132-
min = 1;
133-
}
134-
max = myRules.lowercase.max;
135-
if (typeof myRules.lowercase.max === "undefined") {
136-
max = min;
137-
}
138-
generate = myRules.lowercase.generate;
139-
if (typeof myRules.lowercase.generate !== "undefined") {
140-
min = generate;
141-
max = generate;
142-
}
143-
ruleset += rules.lowercase;
144-
myPassword += rules.lowercase.pick(min,max);
145-
}
146-
if (typeof myRules.letter === "object") {
147-
min = myRules.letter.min;
148-
if (typeof myRules.letter.min === "undefined") {
149-
min = 1;
150-
}
151-
max = myRules.letter.max;
152-
if (typeof myRules.letter.max === "undefined") {
153-
max = min;
154-
}
155-
if (min > myPassword.length) {
156-
min = min - myPassword.length;
157-
} else {
158-
min = 0;
159-
}
160-
if (max > myPassword.length) {
161-
max = max - myPassword.length;
162-
} else {
163-
min = 0;
107+
if (typeof rex_ycom_password_refresh !== 'function') {
108+
function rex_ycom_password_refresh(button) {
109+
110+
var rules = {
111+
letter: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
112+
uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
113+
lowercase: "abcdefghijklmnopqrstuvwxyz",
114+
digit: "0123456789",
115+
symbol: "!@#$%^&*()_+{}:\"<>?\|[];',./`~",
116+
all: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+{}:\"<>?|[];',./`~",
117+
};
118+
rules.letter = rules.uppercase + rules.lowercase;
119+
rules.all = rules.uppercase + rules.lowercase + rules.digit + rules.symbol;
120+
121+
var ruleset = '';
122+
var myRules = JSON.parse(decodeURIComponent(button.getAttribute('data-myRules')));
123+
var myPassword = '';
124+
125+
if (typeof myRules.uppercase === "object") {
126+
min = myRules.uppercase.min;
127+
if (typeof myRules.uppercase.min === "undefined") {
128+
min = 1;
129+
}
130+
max = myRules.uppercase.max;
131+
if (typeof myRules.uppercase.max === "undefined") {
132+
max = min;
133+
}
134+
generate = myRules.uppercase.generate;
135+
if (typeof myRules.uppercase.generate !== "undefined") {
136+
min = generate;
137+
max = generate;
138+
}
139+
ruleset += rules.uppercase;
140+
myPassword += rules.uppercase.pick(min, max);
164141
}
165-
generate = myRules.letter.generate;
166-
if (typeof myRules.letter.max !== "undefined") {
167-
min = generate;
168-
max = generate;
142+
if (typeof myRules.lowercase === "object") {
143+
min = myRules.lowercase.min;
144+
if (typeof myRules.lowercase.min === "undefined") {
145+
min = 1;
146+
}
147+
max = myRules.lowercase.max;
148+
if (typeof myRules.lowercase.max === "undefined") {
149+
max = min;
150+
}
151+
generate = myRules.lowercase.generate;
152+
if (typeof myRules.lowercase.generate !== "undefined") {
153+
min = generate;
154+
max = generate;
155+
}
156+
ruleset += rules.lowercase;
157+
myPassword += rules.lowercase.pick(min, max);
169158
}
170-
myPassword += ruleset.pick(min,max);
159+
if (typeof myRules.letter === "object") {
160+
min = myRules.letter.min;
161+
if (typeof myRules.letter.min === "undefined") {
162+
min = 1;
163+
}
164+
max = myRules.letter.max;
165+
if (typeof myRules.letter.max === "undefined") {
166+
max = min;
167+
}
168+
if (min > myPassword.length) {
169+
min = min - myPassword.length;
170+
} else {
171+
min = 0;
172+
}
173+
if (max > myPassword.length) {
174+
max = max - myPassword.length;
175+
} else {
176+
min = 0;
177+
}
178+
generate = myRules.letter.generate;
179+
if (typeof myRules.letter.max !== "undefined") {
180+
min = generate;
181+
max = generate;
182+
}
183+
myPassword += ruleset.pick(min, max);
171184

172-
}
173-
if (typeof myRules.digit === "object") {
174-
min = myRules.digit.min;
175-
if (typeof myRules.digit.min === "undefined") {
176-
min = 1;
177-
}
178-
max = myRules.digit.max;
179-
if (typeof myRules.digit.max === "undefined") {
180-
max = min;
181185
}
182-
generate = myRules.digit.generate;
183-
if (typeof myRules.digit.max !== "undefined") {
184-
min = generate;
185-
max = generate;
186-
}
187-
ruleset += rules.digit;
188-
myPassword += rules.digit.pick(min,max);
189-
}
190-
if (typeof myRules.symbol === "object") {
191-
min = myRules.symbol.min;
192-
if (typeof myRules.symbol.min === "undefined") {
193-
min = 1;
186+
if (typeof myRules.digit === "object") {
187+
min = myRules.digit.min;
188+
if (typeof myRules.digit.min === "undefined") {
189+
min = 1;
190+
}
191+
max = myRules.digit.max;
192+
if (typeof myRules.digit.max === "undefined") {
193+
max = min;
194+
}
195+
generate = myRules.digit.generate;
196+
if (typeof myRules.digit.max !== "undefined") {
197+
min = generate;
198+
max = generate;
199+
}
200+
ruleset += rules.digit;
201+
myPassword += rules.digit.pick(min, max);
194202
}
195-
max = myRules.symbol.max;
196-
if (typeof myRules.symbol.max === "undefined") {
197-
max = min;
203+
if (typeof myRules.symbol === "object") {
204+
min = myRules.symbol.min;
205+
if (typeof myRules.symbol.min === "undefined") {
206+
min = 1;
207+
}
208+
max = myRules.symbol.max;
209+
if (typeof myRules.symbol.max === "undefined") {
210+
max = min;
211+
}
212+
generate = myRules.symbol.generate;
213+
if (typeof myRules.symbol.max !== "undefined") {
214+
min = generate;
215+
max = generate;
216+
}
217+
ruleset += rules.symbol;
218+
myPassword += rules.symbol.pick(min, max);
198219
}
199-
generate = myRules.symbol.generate;
200-
if (typeof myRules.symbol.max !== "undefined") {
201-
min = generate;
202-
max = generate;
203-
}
204-
ruleset += rules.symbol;
205-
myPassword += rules.symbol.pick(min,max);
206-
}
207220

208-
if (typeof myRules.length === "object") {
209-
min = myRules.length.min;
210-
if (typeof myRules.length.min === "undefined") {
211-
min = 1;
212-
}
213-
max = myRules.length.max;
214-
if (typeof myRules.length.max === "undefined") {
215-
max = min;
216-
}
217-
if (min > myPassword.length) {
218-
min = min - myPassword.length;
219-
} else {
220-
min = 0;
221-
}
222-
if (max > myPassword.length) {
223-
max = max - myPassword.length;
224-
} else {
225-
min = 0;
226-
}
227-
generate = myRules.length.generate;
228-
if (typeof myRules.length.max !== "undefined") {
229-
min = generate;
230-
max = generate;
231-
}
232-
myPassword += ruleset.pick(min,max);
221+
if (typeof myRules.length === "object") {
222+
min = myRules.length.min;
223+
if (typeof myRules.length.min === "undefined") {
224+
min = 1;
225+
}
226+
max = myRules.length.max;
227+
if (typeof myRules.length.max === "undefined") {
228+
max = min;
229+
}
230+
if (min > myPassword.length) {
231+
min = min - myPassword.length;
232+
} else {
233+
min = 0;
234+
}
235+
if (max > myPassword.length) {
236+
max = max - myPassword.length;
237+
} else {
238+
min = 0;
239+
}
240+
generate = myRules.length.generate;
241+
if (typeof myRules.length.max !== "undefined") {
242+
min = generate;
243+
max = generate;
244+
}
245+
myPassword += ruleset.pick(min, max);
233246

234-
}
247+
}
235248

236-
var item = document.getElementsByName('<?= $this->getFieldName() ?>').item(0);
237-
var name = item.getAttribute('name');
238-
var type = item.getAttribute('value');
249+
var item = document.getElementsByName(button.getAttribute('data-myField')).item(0);
250+
var name = item.getAttribute('name');
251+
var type = item.getAttribute('value');
239252

240-
item.value = myPassword;
253+
item.value = myPassword;
241254

255+
}
242256
}
243257
</script><?php
244258

0 commit comments

Comments
 (0)