aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Utils.php
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2016-12-20 11:30:05 +0100
committerGitHub <noreply@github.com>2016-12-20 11:30:05 +0100
commit80677a23e2e10d78bc527e9754286787b453ce61 (patch)
tree18feefc47f389171f3886b191fb14f2ace6d0175 /application/Utils.php
parente350aa750f9e9e742bb60a1e04ebd9e21f763c78 (diff)
parent18e6796726d73d7dc90ecdd16c181493941f5487 (diff)
downloadShaarli-80677a23e2e10d78bc527e9754286787b453ce61.tar.gz
Shaarli-80677a23e2e10d78bc527e9754286787b453ce61.tar.zst
Shaarli-80677a23e2e10d78bc527e9754286787b453ce61.zip
Merge pull request #666 from ArthurHoaro/slim-api
REST API structure using Slim framework
Diffstat (limited to 'application/Utils.php')
-rw-r--r--application/Utils.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/application/Utils.php b/application/Utils.php
index 0a5b476e..62902341 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -231,3 +231,29 @@ function autoLocale($headerLocale)
231 } 231 }
232 setlocale(LC_ALL, $attempts); 232 setlocale(LC_ALL, $attempts);
233} 233}
234
235/**
236 * Generates a default API secret.
237 *
238 * Note that the random-ish methods used in this function are predictable,
239 * which makes them NOT suitable for crypto.
240 * BUT the random string is salted with the salt and hashed with the username.
241 * It makes the generated API secret secured enough for Shaarli.
242 *
243 * PHP 7 provides random_int(), designed for cryptography.
244 * More info: http://stackoverflow.com/questions/4356289/php-random-string-generator
245
246 * @param string $username Shaarli login username
247 * @param string $salt Shaarli password hash salt
248 *
249 * @return string|bool Generated API secret, 12 char length.
250 * Or false if invalid parameters are provided (which will make the API unusable).
251 */
252function generate_api_secret($username, $salt)
253{
254 if (empty($username) || empty($salt)) {
255 return false;
256 }
257
258 return str_shuffle(substr(hash_hmac('sha512', uniqid($salt), $username), 10, 12));
259}