verify($otp); if (PEAR::isError($auth)) { logdie("code=badotp\nstatus=" . $auth->getMessage()); } $sqlid = mysql_real_escape_string($email . " " . $yubikey); $fh = fopen("/dev/urandom", "r") or logdie ("code=openerror"); $rnd = fread ($fh, 20) or logdie ("code=readerror"); fclose ($fh); $b64rnd = base64_encode ($rnd); $query = "SELECT MAX(id) FROM clients"; $result = mysql_query($query, $conn); if (!$result) { debug("SQL query error: " . mysql_error()); logdie("code=maxiderror"); } $id = mysql_fetch_row ($result); mysql_free_result($result); $id = $id[0] + 1; $query = "INSERT INTO clients (id, created, email, otp, secret) " . "VALUES (\"$id\", NOW(), " . mysql_quote($email) . ", " . mysql_quote($otp) . ", " . "\"$b64rnd\")"; if (!mysql_query($query, $conn)) { debug("SQL query error: " . mysql_error()); logdie("code=inserterror"); } mysql_close($conn); debug("Successfully added client ID $id"); echo "code=ok\nid=$id\nkey=$b64rnd\n"; ?>