Fully end to end encrypted anonymous chat program. Server only stores public key lookup for users and the encrypted messages. No credentials are transfered to the server, but kept in local browser storage. This allows 100% safe chatting.
https://safechat.ch
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.6 KiB
49 lines
1.6 KiB
<?php |
|
/*! @file |
|
|
|
@id $Id$ |
|
*/ |
|
// 1 2 3 4 5 6 7 8 |
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890 |
|
|
|
|
|
/// Verify a user |
|
/** Check if a user is consistent to the data in the server's database |
|
or create a user, if he does not yet exist in the usertable |
|
(and the user name is available). |
|
|
|
@param $user user's name |
|
@param $pubkey user's public key |
|
|
|
@return json encoded status with text: |
|
- success() in case of success (user exists or has been created) |
|
- error() in case of mismatch |
|
|
|
@api Verify a User |
|
*/ |
|
function login($user, $pubkey) { |
|
try { |
|
require_once("opendb.php"); |
|
if (!$db) error("database access failed"); |
|
if ($user=="safechat") error("username safechat is reserved for server"); |
|
//$verify = gnupg_import($pgp, $pubkey); |
|
//if (!$verify) error("wrong identity"); |
|
$user = $db->real_escape_string($user); |
|
$pubkey = $db->real_escape_string($pubkey); |
|
$q = $db->query("select * from user where name='$user' and pubkey='$pubkey';"); |
|
if (!$q) error("database query failed"); |
|
if ($q->num_rows==1) { |
|
success("user $user found on server"); |
|
} elseif ($q->num_rows==0) { |
|
$q = $db->query("insert into user (name, pubkey) values ('$user', '$pubkey');"); |
|
if (!$q) error("creation of user failed"); |
|
success("user $user created on server"); |
|
} else { |
|
error("server database defect"); |
|
} |
|
} catch (Exception $e) { |
|
error("login failed"); |
|
} |
|
} |
|
login($_REQUEST['user'], $_REQUEST['pubkey']); |
|
?>
|
|
|