コード例 #1
0
ファイル: auth.php プロジェクト: ncloud/bloglounge
function login($userid, $userpw, $saveId = false) {
	global $database, $db, $service, $event;

	if (!((strlen($userpw) == 40) && preg_match('/[0-9a-f]/i', $userpw))) $forceRaw = true;		
	if (!isset($_SESSION['sslPublicKey']) && !$forceRaw) return false;
	if (Validator::getBool($forceRaw) === true) $userid = sha1($userid);
	
	$db->query('SELECT id, loginid, password, email FROM '.$database['prefix'].'Users WHERE SHA1(loginid)="'.$db->escape($userid).'"');
	if ($db->numRows() != 0) {
		list($uid, $loginid, $password, $email) = $db->fetchRow();
		$db->free();
		$input = array('loginid'=>$loginid, 'email'=>$email, 'saveId'=>$saveId);
		
		if ($password != getEncryptedPassword($loginid, $userpw))
			return false;

		authorizeSession($uid);
		@$db->query('UPDATE '.$database['prefix'].'Users SET lastLogin = UNIX_TIMESTAMP() WHERE loginid="'.$loginid.'"');
		if (!isset($saveId) || empty($saveId)) {
			setcookie('BLOGLOUNGE_LOGINID', '', time() - 31536000, $service['path'] . '/', '.'.$_SERVER['HTTP_HOST']);
		} else {
			setcookie('BLOGLOUNGE_LOGINID', $loginid, time() + 31536000, $service['path'] . '/', '.'.$_SERVER['HTTP_HOST']);
		}
		$event->on('Auth.login', $input);

		return true;
	} 
	return false;
}
    $content = POST("content");
    $_SESSION['title'] = $title;
    $_SESSION['content'] = $content;
}
?>

<?php 
if (SESSION('login') === true) {
    $title = POST("title");
    $content = POST("content");
    $statement = savePost2Database($title, $content);
    showModalNotification("Post saved!", "New post has saved with post id: {$statement}");
} elseif (POST('submit') == 'login') {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $statement = getEncryptedPassword($username);
    $encryptedPassword = "";
    $o = $statement->fetchObject();
    if ($o) {
        $encryptedPassword = $o->password;
    }
    if (strtoupper(md5($password)) == $encryptedPassword) {
        $_SESSION['login'] = true;
        //        $title = POST("title");
        //        $content = POST("content");
        //        global $title, $content;
        $statement = savePost2Database($_SESSION['title'], $_SESSION['content']);
        echo "<h3>Login success, saved!</h3>";
        //        showModalNotification("Login succes", "Welcome $username comes back!", "loginSuccess");
        //        showModalNotification("Post saved!", "New post has saved with post id: $statement", "savePostSuccess");
    } else {