0

当管理员在密码字段的开头或结尾输入空格时,我想显示一条错误消息。但我注意到,当我单击重置按钮时,返回的密码会自动删除字符串开头或结尾的空格。仅检测到中间的空格。

这是 keycloak 管理控制台 UI 我在 pw 字段上做了一个检查元素,我看到了这条线。

<legend><span class="text ng-binding">Manage Password</span></legend>
<div class="form-group">
<label class="col-md-2 control-label ng-binding" for="newPas">New Password


<span class="required ng-hide" data-ng-show="create">*</span></label>
                        <div class="col-md-6">

<input class="form-control password-conceal ng-not-empty ng-dirty ng-valid-parse 
ng-valid ng-valid-required ng-touched" kc-password="" type="text" id="newPas" 
name="newPas" data-ng-model="password" required="">

但是当我在 keycloak 文件上搜索它时,我发现它们是不同的。

<legend><span class="text">{{:: 'manage-user-password' | translate}}</span></legend>
<div class="form-group">
<label class="col-md-2 control-label" for="newPas">{{:: 'new-password' | translate}} 

<span class="required" data-ng-show="create">*</span></label>
<div class="col-md-6">

   <input class="form-control" kc-password type="text" 
id="newPas" name="newPas" data-ng-model="password" required>

这是完整的 html 文件:https ://github.com/keycloak/keycloak/blob/master/themes/src/main/resources/theme/base/admin/resources/partials/user-credentials.html

这是它使用的 angularjs 代码:

$scope.resetPassword = function() {
        // hit enter without entering both fields - ignore
        if (!$scope.passwordAndConfirmPasswordEntered()) return;

        if ($scope.pwdChange) {
            if ($scope.password != $scope.confirmPassword) {
                Notifications.error("Password and confirmation does not match.");
                return;
            }
        }

        var msgTitle = 'Change password';
        var msg = 'Are you sure you want to change the users password?';

        Dialog.confirm(msgTitle, msg, function() {
            UserCredentials.resetPassword({ realm: realm.realm, userId: user.id }, 
{ type : "password", value : $scope.password, temporary: $scope.temporaryPassword }, function() {
                    Notifications.success("The password has been reset  test"+$scope.password); 
//here i confirmed that the returned password automatically removes the spaces in beginning and end. 
Only spaces in between are accepted.


                        $scope.password = null;
                        $scope.confirmPassword = null;
                        $route.reload();
                    });
                }, function() {
                    $scope.password = null;
                    $scope.confirmPassword = null;
                });
            };

            $scope.passwordAndConfirmPasswordEntered = function() {
                return $scope.password && $scope.confirmPassword;
            }

这是完整的 js 脚本:https ://github.com/keycloak/keycloak/blob/master/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js

请帮助我找到keycloak如何删除我在密码开头或结尾输入的空格!谢谢

在这里,即使我在开头输入空格,我也显示密码没有返回空格:

4

1 回答 1

0

找到了!供参考:AngularJS - 使用正则表达式从输入框中删除前导和尾随空格

Angularjs 默认在密码字段中使用 ng-trim = true。所以我将密码输入设置为 ng-trim = "false" 并且它起作用了!

于 2018-04-05T10:33:23.070 回答