diff --git a/include/User.h b/include/User.h index 58d170f3a5..38c105d421 100644 --- a/include/User.h +++ b/include/User.h @@ -21,6 +21,7 @@ #include "UserTemplate.h" #include "ObjectCollection.h" #include "QuotasSQL.h" +#include "NebulaUtil.h" class UserQuotas; @@ -112,22 +113,7 @@ public: * @param error_str Returns the error reason, if any * @returns -1 if the password is not valid */ - int set_password(const string& passwd, string& error_str) - { - int rc = 0; - - if (pass_is_valid(passwd, error_str)) - { - password = passwd; - invalidate_session(); - } - else - { - rc = -1; - } - - return rc; - }; + int set_password(const string& passwd, string& error_str); /** * Returns user password diff --git a/src/rm/RequestManagerUser.cc b/src/rm/RequestManagerUser.cc index 03ab3f6316..e6ffa49635 100644 --- a/src/rm/RequestManagerUser.cc +++ b/src/rm/RequestManagerUser.cc @@ -15,7 +15,6 @@ /* -------------------------------------------------------------------------- */ #include "RequestManagerUser.h" -#include "NebulaUtil.h" using namespace std; @@ -70,11 +69,6 @@ int UserChangePassword::user_action(int user_id, return -1; } - if (user->get_auth_driver() == UserPool::CORE_AUTH) - { - new_pass = one_util::sha1_digest(new_pass); - } - int rc = user->set_password(new_pass, error_str); if ( rc == 0 ) @@ -125,22 +119,13 @@ int UserChangeAuth::user_action(int user_id, return -1; } - if ( !new_pass.empty() ) - { - if ( new_auth == UserPool::CORE_AUTH) - { - new_pass = one_util::sha1_digest(new_pass); - } + rc = user->set_auth_driver(new_auth, error_str); - // The password may be invalid, try to change it first + if ( rc == 0 && !new_pass.empty() ) + { rc = user->set_password(new_pass, error_str); } - if ( rc == 0 ) - { - rc = user->set_auth_driver(new_auth, error_str); - } - if ( rc == 0 ) { pool->update(user); diff --git a/src/um/User.cc b/src/um/User.cc index 6376d9bb0d..77e68ccc0a 100644 --- a/src/um/User.cc +++ b/src/um/User.cc @@ -338,6 +338,32 @@ int User::split_secret(const string secret, string& user, string& pass) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int User::set_password(const string& passwd, string& error_str) +{ + int rc = 0; + + if (pass_is_valid(passwd, error_str)) + { + if (auth_driver == UserPool::CORE_AUTH) + { + password = one_util::sha1_digest(passwd); + } + else + { + password = passwd; + } + + invalidate_session(); + } + else + { + rc = -1; + } + + return rc; +}; + + bool User::pass_is_valid(const string& pass, string& error_str) { if ( pass.empty() )