You are here

function shurly_generate_new_api_key in ShURLy 6

Same name and namespace in other branches
  1. 8 shurly_service/shurly_api_keys.inc \shurly_generate_new_api_key()
  2. 7 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

2 calls 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.
shurly_service_get_key in shurly_service/shurly_service.inc

File

shurly_service/shurly_api_keys.inc, line 10

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 = %d', $uid);
  $result = db_query("INSERT INTO {shurly_keys} (uid, apikey) VALUES (%d,'%s')", $uid, $key);
  return $result ? $key : FALSE;
}