diff options
| author | Michael Klishin <mklishin@pivotal.io> | 2016-12-30 03:56:57 +0800 |
|---|---|---|
| committer | Michael Klishin <mklishin@pivotal.io> | 2016-12-30 03:56:57 +0800 |
| commit | 634a53f44a4795baa68a0b654e71210e5589b524 (patch) | |
| tree | e0d95848b1a84d558f9377eb1d5bbbb233f4fff1 /src | |
| parent | f2012f2d9b07b8e92549cb115541e3af507e8083 (diff) | |
| download | rabbitmq-server-git-634a53f44a4795baa68a0b654e71210e5589b524.tar.gz | |
Introduce rabbit_credential_validator_regexp
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_credential_validator_regexp.erl | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/rabbit_credential_validator_regexp.erl b/src/rabbit_credential_validator_regexp.erl new file mode 100644 index 0000000000..187e679416 --- /dev/null +++ b/src/rabbit_credential_validator_regexp.erl @@ -0,0 +1,48 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. +%% + +-module(rabbit_credential_validator_regexp). + +-include("rabbit.hrl"). + +-behaviour(rabbit_credential_validator). + +%% +%% API +%% + +-export([validate_password/1]). +%% for tests +-export([validate_password/2]). + +-spec validate_password(rabbit_types:password()) -> 'ok' | {'error', string(), [any()]}. + +validate_password(Password) -> + Proplist = application:get_env(rabbit, credential_validator), + Regexp = case proplists:get_value(regexp, Proplist) of + undefined -> {error, "rabbit.credential_validator.regexp config key is undefined"}; + Value -> rabbit_data_coercion:to_list(Value) + end, + validate_password(Password, Regexp). + + +-spec validate_password(rabbit_types:password(), string()) -> 'ok' | {'error', string(), [any()]}. + +validate_password(Password, Pattern) -> + case re:run(Password, Pattern) of + {match, _} -> ok; + nomatch -> {error, "provided password does not match the validator regular expression"} + end. |
