function shurly_generate_new_api_key in ShURLy 7
Same name and namespace in other branches
- 8 shurly_service/shurly_api_keys.inc \shurly_generate_new_api_key()
- 6 shurly_service/shurly_api_keys.inc \shurly_generate_new_api_key()
Generate a new api key for this user and put it into the database
Return value
the new API key or FALSE on database insert error
1 call to shurly_generate_new_api_key()
- shurly_api_key_form_submit in shurly_service/
shurly_service.module - Submit handler for shurly_api_key_form(). Regenerate a user API key.
File
- shurly_service/
shurly_api_keys.inc, line 13
Code
function shurly_generate_new_api_key($uid) {
// be sure that the new key is unique
do {
$key = md5(uniqid(rand(), TRUE)) . '_' . API_VERSION;
} while (shurly_get_uid($key));
db_query('DELETE FROM {shurly_keys} WHERE uid = :uid', array(
'uid' => $uid,
));
$result = db_query("INSERT INTO {shurly_keys} (uid, apikey) VALUES (:uid, :key)", array(
'uid' => $uid,
'key' => $key,
));
return $result ? $key : FALSE;
}