Example #1
0
 // 2段階認証の状態を取得
 $session_twostep = 0;
 if ($twostep == 1 && isset($_COOKIE['auth']['session'])) {
     $sessions = select_sessions(array('select' => 'twostep', 'where' => array('id = :session AND user_id = :user_id', array('session' => $_COOKIE['auth']['session'], 'user_id' => $id))));
     if (!empty($sessions)) {
         $session_twostep = $sessions[0]['twostep'];
     }
 }
 // 2段階認証
 if ($twostep == 1 && $session_twostep == 0) {
     $_view['user'] = $_POST;
     $_view['twostep'] = true;
     $success = false;
     if (isset($_POST['twostep_code'])) {
         // 2段階認証用コードを確認
         $users = select_users(array('select' => 'id, twostep_expire', 'where' => array('username = :username AND password = :password AND twostep_code = :twostep_code', array('username' => $_POST['username'], 'password' => hash_crypt($_POST['password'], $password_salt . ':' . $GLOBALS['config']['hash_salt']), 'twostep_code' => $_POST['twostep_code']))));
         if (empty($users)) {
             $_view['warnings'] = array('2段階認証用コードが違います。');
         } else {
             if (localdate(null, $users[0]['twostep_expire']) < localdate()) {
                 $_view['warnings'] = array('2段階認証用コードの有効期限が終了しています。');
             } else {
                 $success = true;
             }
         }
     } else {
         // 2段階認証用コードを作成
         $twostep_code = rand_string(6);
         // トランザクションを開始
         db_transaction();
         // 2段階認証用コードを通知
Example #2
0
// パスワードのソルトを作成
$password_salt = hash_salt();
// トランザクションを開始
db_transaction();
// メールアドレスを取得
$users = select_users(array('select' => 'email', 'where' => array('id = :id', array('id' => $_SESSION['auth']['user']['id']))));
// メールアドレスの変更を確認
if ($_SESSION['post']['user']['email'] === $users[0]['email']) {
    $email_activated = 1;
} else {
    $email_activated = 0;
}
// ユーザを編集
$sets = array('username' => $_SESSION['post']['user']['username'], 'email' => $_SESSION['post']['user']['email'], 'email_activated' => $email_activated);
if (!empty($_SESSION['post']['user']['password'])) {
    $sets['password'] = hash_crypt($_SESSION['post']['user']['password'], $password_salt . ':' . $GLOBALS['config']['hash_salt']);
    $sets['password_salt'] = $password_salt;
}
$resource = update_users(array('set' => $sets, 'where' => array('id = :id', array('id' => $_SESSION['auth']['user']['id']))), array('id' => intval($_SESSION['auth']['user']['id']), 'update' => $_SESSION['update']['user']));
if (!$resource) {
    error('データを編集できません。');
}
// プロフィールを編集
$resource = update_profiles(array('set' => array('name' => $_SESSION['post']['profile']['name'], 'text' => $_SESSION['post']['profile']['text']), 'where' => array('user_id = :user_id', array('user_id' => $_SESSION['auth']['user']['id']))), array('id' => intval($_SESSION['auth']['user']['id']), 'update' => $_SESSION['update']['user']));
if (!$resource) {
    error('データを編集できません。');
}
// トランザクションを終了
db_commit();
// 投稿セッションを初期化
unset($_SESSION['post']);
Example #3
0
<?php

import('libs/plugins/hash.php');
// フォワードを確認
if (forward() === null) {
    error('不正なアクセスです。');
}
// 投稿データを確認
if (empty($_SESSION['post'])) {
    // リダイレクト
    redirect('/password');
}
// トランザクションを開始
db_transaction();
// パスワードのソルトを作成
$password_salt = hash_salt();
// ユーザを編集
$resource = update_users(array('set' => array('password' => hash_crypt($_SESSION['post']['user']['password'], $password_salt . ':' . $GLOBALS['config']['hash_salt']), 'password_salt' => $password_salt, 'token' => null, 'token_code' => null, 'token_expire' => null), 'where' => array('email = :email', array('email' => $_SESSION['post']['user']['key']))), array('id' => intval($_SESSION['post']['user']['id']), 'update' => $_SESSION['update']['user']));
if (!$resource) {
    error('データを編集できません。');
}
// トランザクションを終了
db_commit();
// 投稿セッションを初期化
unset($_SESSION['post']);
unset($_SESSION['update']);
unset($_SESSION['expect']);
// リダイレクト
redirect('/password/complete');
Example #4
0
<?php

import('libs/plugins/hash.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // パスワードのソルトを取得
    $users = select_users(array('select' => 'password_salt', 'where' => array('id = :id', array('id' => $_SESSION['auth']['user']['id']))));
    if (empty($users)) {
        $password_salt = null;
    } else {
        $password_salt = $users[0]['password_salt'];
    }
    // パスワード認証
    $users = select_users(array('select' => 'id, twostep, twostep_email', 'where' => array('id = :id AND password = :password', array('id' => $_SESSION['auth']['user']['id'], 'password' => hash_crypt($_POST['password'], $password_salt . ':' . $GLOBALS['config']['hash_salt'])))));
    if (empty($users)) {
        // パスワード認証失敗
        $_view['user'] = $_POST;
        $_view['warnings'] = array('パスワードが違います。');
    } else {
        $_SESSION['auth']['password'] = true;
        // リダイレクト
        redirect('/user/password');
    }
}
// タイトル
$_view['title'] = 'パスワード再入力サンプル';
Example #5
0
import('libs/plugins/hash.php');
// フォワードを確認
if (forward() === null) {
    error('不正なアクセスです。');
}
// 投稿データを確認
if (empty($_SESSION['post'])) {
    // リダイレクト
    redirect('/register');
}
// パスワードのソルトを作成
$password_salt = hash_salt();
// トランザクションを開始
db_transaction();
// ユーザを登録
$resource = insert_users(array('values' => array('username' => $_SESSION['post']['user']['username'], 'password' => hash_crypt($_SESSION['post']['user']['password'], $password_salt . ':' . $GLOBALS['config']['hash_salt']), 'password_salt' => $password_salt, 'email' => $_SESSION['post']['user']['email'])));
if (!$resource) {
    error('データを登録できません。');
}
// IDを取得
$user_id = db_last_insert_id();
// プロフィールを登録
$resource = insert_profiles(array('values' => array('user_id' => $user_id)));
if (!$resource) {
    error('データを登録できません。');
}
// トランザクションを終了
db_commit();
// 投稿セッションを初期化
unset($_SESSION['post']);
// リダイレクト