diff --git a/src/shared/libcrypt-util.c b/src/shared/libcrypt-util.c index b1a8168030..f41685ae45 100644 --- a/src/shared/libcrypt-util.c +++ b/src/shared/libcrypt-util.c @@ -73,3 +73,14 @@ int make_salt(char **ret) { return 0; #endif } + +bool hashed_password_valid(const char *s) { + + /* Returns true if the specified string is a 'valid' hashed UNIX password, i.e. if starts with '$' or + * with '!$' (the latter being a valid, yet locked password). */ + + if (isempty(s)) + return false; + + return STARTSWITH_SET(s, "$", "!$"); +} diff --git a/src/shared/libcrypt-util.h b/src/shared/libcrypt-util.h index 3da1ab5ad9..93f0e13ffb 100644 --- a/src/shared/libcrypt-util.h +++ b/src/shared/libcrypt-util.h @@ -18,3 +18,5 @@ #include int make_salt(char **ret); + +bool hashed_password_valid(const char *s);