public static function getipaddress($ip = null) { if ($ip) { $validate = new Validate(["ip" => "ip"]); if (!$validate->check($ip)) { //验证无法通过 $ip = null; } } self::$config = array_merge(self::$config, ["ip" => $ip]); $class = '\\think\\driver\\' . ucwords(self::$config["type"]); self::$handler = new $class(self::$config); return self::$handler->getipaddress(); }
public function set($data) { foreach ($data as $key => $value) { $this->_fields[$key] = $value; } if (isset($this->schema)) { $validate = new Validate(); $validate->check($this->_fields, $this->schema, $this->_identifier); if (!$validate->passed()) { $this->_errors = $validate->errors(); } } $this->clean(); }
public function save_step2() { $validate = new Validate(); $source = $_POST; $items = array('fb-app-id' => array('required' => true), 'fb-app-secret-id' => array('required' => true)); $validate->check($source, $items); if (!$validate->passed()) { echo "Please provide all required <span class='required'>*</span> fields."; return; } $this->loadmodel("install"); if ($this->model->step2()) { echo "Success"; } }
/** * Validates the stored fields in session based on the given form id. */ public function validate() { $formId = $_POST['form_id']; $data = Cache::get($formId); if ($data) { $fields = unserialize($data); foreach ($fields as $fieldName => $fieldData) { if (isset($fieldData['validate'])) { Validate::check($fieldName, $fieldData['validate']); } } return Validate::passed(); } return false; }
public function action_recover() { $get = new Validate($_GET); $get->rules('id', array('not_empty' => array(), 'numeric' => array())); $get->rules('key', array('not_empty' => array(), 'alpha_numeric' => array())); if ($get->check()) { $user = ORM::factory('user')->where('id', '=', $get['id'])->where('activation_key', '=', $get['key'])->where('activation_expire', '>=', date('YmdHis'))->find(); if ($user->loaded()) { $user->activation_key = null; $user->activation_expire = null; $user->save(); $this->authentic->force_login($user); $this->request->redirect('settings'); } } throw new Kohana_404_Exception('Bad Request'); }
/** * Used to run the admin install if it hasn't been created yet. */ public static function install() { if ($_POST) { Validate::check('email', array('email')); Validate::check('password', array('required')); Validate::check('conf_password', array('matches:password')); if (Validate::passed()) { $userId = User::user()->insert(array('email' => $_POST['email'], 'pass' => md5($_POST['password']), 'is_admin' => 1)); if ($userId) { Message::ok('Admin install complete.'); Url::redirect('admin/login'); } else { Message::error('Error creating admin account. Please try again.'); } } } }
function createPage($smarty) { if (Users::loggedIn()) { Redirect::to('?page=profile'); } if (Input::exists()) { if (Input::get('action') === 'register') { $validation = new Validate(); $validation->check($_POST, array_merge(Config::get('validation/register_info'), Config::get('validation/set_password'))); if ($validation->passed()) { try { Users::create(array('student_id' => Input::get('sid'), 'password' => Hash::hashPassword(Input::get('password')), 'permission_group' => 1, 'name' => Input::get('name'), 'email' => Input::get('email'), 'umail' => Input::get('sid') . '@umail.leidenuniv.nl', 'phone' => Phone::formatNumber(Input::get('phone')), 'joined' => DateFormat::sql())); Users::login(Input::get('sid'), Input::get('password')); Notifications::addSuccess('You have been succesfully registered!'); Redirect::to('?page=profile'); } catch (Exception $e) { Notifications::addError($e->getMessage()); } } else { Notifications::addValidationFail($validation->getErrors()); } } if (Input::get('action') === 'login') { $validation = new Validate(); $validation->check($_POST, Config::get('validation/login')); if ($validation->passed()) { $login = Users::login(Input::get('sid'), Input::get('password'), Input::getAsBool('remember')); if ($login) { Notifications::addSuccess('You have been logged in!'); Redirect::to('?page=profile'); } else { Notifications::addValidationFail('Invalid student number or password.'); } } else { Notifications::addValidationFail($validation->getErrors()); } } } $smarty->assign('remember', Input::getAsBool('remember')); $smarty->assign('name', Input::get('name')); $smarty->assign('sid', Input::get('sid')); $smarty->assign('email', Input::get('email')); $smarty->assign('phone', Input::get('phone')); return $smarty; }
public function action_verify() { $get = new Validate($_GET); $get->rules('id', array('not_empty' => array(), 'numeric' => array())); $get->rules('key', array('not_empty' => array(), 'alpha_numeric' => array())); if ($get->check()) { $user = ORM::factory('user')->where('id', '=', $get['id'])->where('activation_key', '=', $get['key'])->find(); if ($user->loaded()) { $user->activation_key = null; $user->activation_expire = null; $user->email_verified = 'True'; $user->save(); $this->authentic->force_login($user); $this->request->redirect('settings'); } } $this->request->redirect('login'); }
public function register() { if ($this->isPost()) { $email = trim($_POST['email']); $password = trim($_POST['password']); $password2 = trim($_POST['password_repeat']); if ($password != $password2) { $this->putErrorMsg('两次密码不一致'); } if (!preg_match('/[0-9a-zA-Z_\\.\\@\\#\\$\\%]{6,18}/', $password)) { $this->putErrorMsg('/[0-9a-zA-Z_\\.\\@\\#\\$\\%]{6,18}/'); } if (empty($email)) { $this->putErrorMsg('email不能为空'); } else { if (true != Validate::check($email, 'varchar', '1_email')) { $this->putMsg('不是email'); } } if ($this->isErrorMsgEmpty()) { $userModelDB = new UserModelDB(); $r = $userModelDB->save($email, sha1($password)); $uid = $userModelDB->insertId(); if ($r) { $this->putmsg('注册成功'); $um = new UserModel(); $succ = $um->setUserCookie(array('email' => $email, 'uid' => $uid)); if (!$succ) { $this->putErrorMsg('您居然把cookie关了...'); } } else { $this->putErrorMsg('注册失败' . $r); } } } var_dump($this->getMsg()); var_dump($this->getErrorMsg()); $this->setView('msg', $this->getMsg()); $this->setView('errorMsg', $this->getErrorMsg()); $this->display('register.html'); }
/** * Processes an uploaded image * * @return null */ public function action_upload() { // Validate the upload first $validate = new Validate($_FILES); $validate->rules('image', array('Upload::not_empty' => null, 'Upload::valid' => null, 'Upload::size' => array('4M'), 'Upload::type' => array(array('jpg', 'png', 'gif')))); if ($validate->check(true)) { // Shrink the image to the lowest max dimension $image = Image::factory($_FILES['image']['tmp_name']); $constraints = Kohana::config('image')->constraints; $image->resize($constraints['max_width'], $constraints['max_height']); $image->save(APPPATH . 'photos/' . $_FILES['image']['name']); $photo = new Model_Vendo_Photo(); $photo->file = APPPATH . 'photos/' . $_FILES['image']['name']; $photo->save(); unlink(APPPATH . 'photos/' . $_FILES['image']['name']); $this->request->redirect('admin/photo'); } else { Session::instance()->set('errors', $validate->errors('validate')); $this->request->redirect('admin/photo'); } }
function changePassword() { $input = Input::parse(); if (Token::check($input['token'])) { $validate = new Validate(); $validate->check($input, array('password_current' => ['required' => true, 'min' => 6], 'password' => ['required' => true, 'min' => 6], 'password_repeat' => ['required' => true, 'min' => 6, 'matches' => 'password'])); if ($validate->passed()) { $user = new User(); if (Hash::make($input['password_current'], config::get('encryption/salt')) !== $user->data()->password) { echo "incorrent password"; } else { $user->update(array('password' => Hash::make($input['password'], config::get('ecryption/salt')))); Session::flash('success', 'Successfully changed password'); Redirect::to('changepassword'); } } else { Session::flash('error', $validate->errors()); Redirect::to('changepassword'); } } }
public function validate($method = self::REQUEST) { /** * Контейнер который будет модержать в себе имена проверяемых полей и * результат проверки в виде: * name => true, name2 => false */ $a_valid = []; // Статус валидации $this->_status = true; $validate = new Validate(); $validate->setMethod($method); foreach ($this->_fields as $name => $field) { $valid = $validate->check($field); $a_valid[$name] = (bool) $valid; if (!$valid) { $this->_status = false; } } $this->_valid_status = $a_valid; return $this->_status; }
function signup() { $input = Input::parse(); if (Token::check($input['token'])) { $validate = new Validate(); $validate->check($input, array('username' => ['required' => true, 'min' => 5, 'max' => 20, 'unique' => 'users'], 'name' => ['required' => true, 'max' => 50], 'password' => ['required' => true, 'min' => 6])); if ($validate->passed()) { $user = new User(); $salt = config::get("encription/hash"); try { $user->create(array('username' => $input['username'], 'password' => Hash::make($input['password']), 'name' => $input['name'], 'joined' => date('Y-m-d H:i:s'), 'group_id' => 1)); } catch (Exception $e) { die($e->getMessage()); } Session::flash('login', 'You registered successfully! Please login!'); Redirect::to('login'); } else { Session::flash('error', $validate->errors()); Redirect::to('signup'); } } else { echo "Invalid token"; } }
</head> <body> <form action="" method="post"> <h1>Log in</h1> <div class="inset"> <?php if (Input::exists('post')) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array( 'username' => array( 'required' => true, 'name' => 'username' ), 'password' => array( 'required' => true, 'name' => 'password' ) )); if ($validation->passed()) { $user = new User(); $remember = (Input::get('remember') === 'on') ? true : false; $login = $user->login(Input::get('username'), Input::get('password'), $remember); if ($login) { Redirect::to('index.php'); } else { echo '<p>Sorry, logging in failed </p>';
<?php /** * Created by Chris on 9/29/2014 3:53 PM. */ require_once 'core/init.php'; $user = new User(); if (!$user->isLoggedIn()) { Redirect::to('index.php'); } if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('current_password' => array('required' => true, 'min' => 6), 'new_password' => array('required' => true, 'min' => 6), 'new_password_again' => array('required' => true, 'min' => 6, 'matches' => 'new_password'))); if ($validate->passed()) { if (Hash::make(Input::get('current_password'), $user->data()->salt) !== $user->data()->password) { Session::flash('error', 'Your current password is incorrect.'); Redirect::to('changepassword.php'); } else { $salt = Hash::salt(32); $user->update(array('password' => Hash::make(Input::get('new_password'), $salt), 'salt' => $salt)); Session::flash('success', 'Your password has been changed!'); Redirect::to('index.php'); } } else { foreach ($validate->errors() as $error) { echo $error, '<br>'; } } } }
<?php require_once 'core/init.php'; if (Input::exists('post')) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('taskid' => array('required' => true, 'name' => 'taskid'))); if ($validation->passed()) { $teacher = new Teacher(); $id = Input::get('taskid'); try { $teacher->_taskOperation->taskDelete($id); Session::flash("course", "删除成功"); Redirect::to('course.php'); } catch (Exception $e) { die('error' . $e->getMessage()); Session::flash("course", "删除失败"); Redirect::to('course.php'); } } else { $errorInfo = ''; foreach ($validation->errors() as $error) { //echo $error; $errorInfo .= $error . '<br>'; } Session::flash("course", "删除失败"); Redirect::to('course.php'); } } }
<h3><strong>Recover Password</strong></h3> <?php $user = new User(); $notification = new smsNotification(); $file = new accessFile(); $pNum = $_SESSION['phone']; $id = $_SESSION['id']; //try{ //$randomValue = $_SESSION['rSend']; //} catch (customException $e){} $randomValue = isset($_SESSION['rSend']) ? $_SESSION['rSend'] : ''; if (!isset($_POST['data'])) { if (Token::check(Input::get('token'))) { $hiddenValue = Input::get('storeRandVal'); $validate = new Validate(); $validation = $validate->check($_POST, array('rand_number' => array('required' => true, 'min' => 4, 'max' => 4))); if ($validation->passed()) { $input = htmlspecialchars(trim(Input::get('rand_number'))); if ($input == $hiddenValue) { //Session::flash('home', 'Your code is correct.'); Redirect::to('forgetpassCheckPoint2.php'); } elseif ($randomValue != $hiddenValue) { // Session::flash('home', 'you enter wrong key code.'); // Redirect::to('index.php'); echo "<script>alert('Invalid key code. Please try again');</script>"; // Redirect::to('forgetpassCheckPoint.php'); } else { echo "<script>alert('Invalid key code. Please try again');</script>"; } } else { $str = "";
$recaptchaEnabled = Config::get('google_recaptcha/enabled') === '1' ? true : null; if ($recaptchaEnabled) { // include reCAPTCHA API echo '<script src="https://www.google.com/recaptcha/api.js?hl=ru"></script>'; // include a library that handles calling Google reCAPTCHA require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . 'recaptcha.php'; } /** * establish error handler outside the following if block because * of a need to output error information to the user **/ $errorHandler = new ErrorHandler(); if (Input::exists()) { if (Token::check(Input::get('token'))) { $validator = new Validate($errorHandler); $validator->check($_POST, ['address' => ['required' => true, 'minLength' => 5, 'maxLength' => 240], 'customer_name' => ['required' => true, 'minLength' => 8, 'maxLength' => 120], 'quantity' => ['digit' => true], 'info' => ['maxLength' => 600]]); /** * Google reCAPTCHA check (if enabled in config.ini) **/ if ($recaptchaEnabled) { $reCaptcha = new ReCaptcha(Config::get('google_recaptcha/secret_key')); // Was there a proper reCAPTCHA response? if (Input::found('g-recaptcha-response')) { $response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], Input::get('g-recaptcha-response')); } else { $response = null; } if ($response === null || $response->success !== true) { $message = 'Пожалуйста, подтвердите, что вы не робот.<span class="smile">☺</span>'; $errorHandler->addError($message, 'recaptcha'); }
try { $queries->delete('vote_sites', array('id', '=', $_GET["vid"])); echo '<script>window.location.replace("/admin/vote");</script>'; die; } catch (Exception $e) { die($e->getMessage()); } } } } else { if (isset($_GET["vid"])) { if (Input::exists()) { if (Token::check(Input::get('token'))) { if (Input::get('action') === "update") { $validate = new Validate(); $validation = $validate->check($_POST, array('vote_name' => array('required' => true, 'min' => 2, 'max' => 64), 'vote_url' => array('required' => true, 'min' => 2, 'max' => 255))); if ($validation->passed()) { try { $queries->update('vote_sites', $_GET["vid"], array('name' => htmlspecialchars(Input::get('vote_name')), 'site' => str_replace("&", "&", htmlspecialchars(Input::get('vote_url'))))); echo '<script>window.location.replace("/admin/vote/?vid=' . $_GET["vid"] . '");</script>'; die; } catch (Exception $e) { die($e->getMessage()); } } else { echo '<div class="alert alert-danger">'; foreach ($validation->errors() as $error) { echo $error, '<br>'; } echo '</div>'; }
// HTML Purifier for page content // Admin check if ($user->isAdmLoggedIn()) { // Is authenticated if ($user->data()->group_id != 2) { Redirect::to('/'); die; } } else { Redirect::to('/admin'); die; } if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('url' => array('required' => true, 'min' => 1, 'max' => 20), 'title' => array('required' => true, 'min' => 1, 'max' => 30), 'content' => array('required' => true, 'min' => 5, 'max' => 20480))); if ($validation->passed()) { if ($_GET["page"] == 1) { $url = "/help/"; // Can't change the URL for the help page $title = "Help"; } else { $url = Input::get('url'); $title = Input::get('title'); } try { $queries->update("custom_pages", $_GET["page"], array("url" => htmlspecialchars($url), "title" => htmlspecialchars($title), "content" => htmlspecialchars(Input::get('content')))); } catch (Exception $e) { die($e->getMessage()); } } else {
<?php require_once 'core/init.php'; $user = new User(); if (Input::exists('post') && $user->isLoggedIn()) { $data = Input::get('data'); $validate = new Validate(); $validation = $validate->check($data, array('receiver' => array('name' => 'receiver', 'required' => true), 'context' => array('name' => 'context', 'required' => true))); if ($validation->passed()) { $postId = $data['postId']; $reply = new DBReply(); $receiver = $data['receiver']; $context = $data['context']; if (array_key_exists("imgs", $data)) { $imgs = implode("|", $data['imgs']); } else { $imgs = ''; } try { $reply->create(array('post_id' => $postId, 'context' => $context, 'imgs' => $imgs, 'reply_time' => date('Y-m-d H:i:s'), 'sender' => $user->data()->id, 'receiver' => $receiver)); Session::delete('post'); //Session::flash('forum','create post successfully'); Session::flash('post', "回帖成功"); echo 'success'; //Redirect::to('index.php'); } catch (Exception $e) { die($e->getMessage()); } } else { echo 'empty'; }
<?php require_once 'core/init.php'; $user = new User(); if (!$user->isLoggedIn()) { Redirect::to('index.php'); } if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('name' => array('required' => true, 'min' => 2, 'max' => 50))); if ($validation->passed()) { // update try { $user->update(array('name' => Input::get('name'))); Session::flash('home', 'je gegevens zijn bijgewerkt.'); Redirect::to('index.php'); } catch (Exception $e) { die($e->getMessage()); } } else { foreach ($validation->errors() as $error) { echo $error, '<br>'; } } } } ?> <form action="" method="post"> <div class="field"> <label for="name">Naam</label>
<?php /** * This is the script which is run once the user clicks the login/sign in button. If any post data exists the data is validated against the requirements. * If the user validation is passed then user is logged in, otherwise errors are echoed to the user. * * Created 23rd December 2014 * @author Vikram Bakshi */ require_once 'init.php'; if (Input::exists('post')) { $validate = new Validate(); $validation = $validate->check($_POST, array('nhsnumber' => array('required' => true, 'min' => 5, 'max' => 15), 'password' => array('required' => true))); if ($validation->passed()) { $user = new User(); $remember = Input::get('remember') === 'remember' ? true : false; //did the user tick the remember me button? $login = $user->login(Input::get('nhsnumber'), Input::get('password'), true); if ($login) { echo "<br />You have logged in successfully! You will be redirected in 5 seconds. <br/>\n\t\t\t\t\tIf you are not redirected please " . '<a href="../../../home.html">' . 'click here' . '</a>'; header("refresh:5;url=../../../home.html"); } else { 'Log In Failed. Please check your username/nhsnumber and password.'; } } else { foreach ($validation->getErrors() as $error) { echo $error, '<br />'; } } }
die; } // Get the topic information $topic = $queries->getWhere("topics", array("id", "=", $tid)); $topic = $topic[0]; // Can the user post a reply in this topic? $can_reply = $forum->canPostReply($topic->forum_id, $user->data()->group_id); if (!$can_reply) { Redirect::to('/forum/view_topic/?tid=' . $tid); die; } // Deal with inputted data if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('content' => array('required' => true, 'min' => 2, 'max' => 20480))); if ($validation->passed()) { try { $queries->create("posts", array('forum_id' => $fid, 'topic_id' => $tid, 'post_creator' => $user->data()->id, 'post_content' => htmlspecialchars(Input::get('content')), 'post_date' => date('Y-m-d H:i:s'))); // Get last post ID $last_post_id = $queries->getLastId(); $content = $mentionsParser->parse(Input::get('content'), $tid, $last_post_id, $user_language); $queries->update("posts", $last_post_id, array('post_content' => $content)); $queries->update("forums", $fid, array('last_topic_posted' => $tid, 'last_user_posted' => $user->data()->id, 'last_post_date' => date('Y-m-d H:i:s'))); $queries->update("topics", $tid, array('topic_last_user' => $user->data()->id, 'topic_reply_date' => date('U'))); Session::flash('success_post', '<div class="alert alert-info alert-dismissable"> <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span></button>' . $forum_language['post_submitted'] . '</div>'); Redirect::to('/forum/view_topic/?tid=' . $tid); die; } catch (Exception $e) { die($e->getMessage()); }
/* * Made by Samerton * http://worldscapemc.co.uk * * License: MIT */ if (!$user->isLoggedIn()) { Redirect::to('/'); die; } require 'inc/includes/html/library/HTMLPurifier.auto.php'; // HTMLPurifier if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('screenname' => array('required' => true, 'min' => 2, 'max' => 20), 'signature' => array('max' => 256, 'required' => true))); if ($validation->passed()) { try { $queries->update('users', $user->data()->id, array('username' => htmlspecialchars(Input::get('screenname')), 'signature' => htmlspecialchars(Input::get('signature')))); Redirect::to('/user/settings'); die; } catch (Exception $e) { die($e->getMessage()); } } else { $error_string = ""; foreach ($validation->errors() as $error) { $error_string .= ucfirst($error) . '<br />'; } Session::flash('usercp_settings', '<div class="alert alert-danger">' . $error_string . '</div>'); }
<?php /** * Created by Chris on 9/29/2014 3:53 PM. */ require_once 'core/init.php'; $user = new User(); if ($user->isLoggedIn()) { Redirect::to('index.php'); } if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('name' => array('field_name' => 'Name', 'required' => true, 'min' => 2, 'max' => 50), 'username' => array('field_name' => 'Username', 'required' => true, 'min' => 2, 'max' => 20, 'unique' => 'users'), 'email' => array('field_name' => 'Email', 'required' => true, 'min' => 1, 'max' => 255, 'unique' => 'users'), 'password' => array('field_name' => 'Password', 'required' => true, 'min' => 6), 'password_again' => array('field_name' => 'Repeated Password', 'required' => true, 'matches' => 'password_again'))); if ($validate->passed()) { $user = new User(); $salt = Hash::salt(32); try { $user->create(array('name' => Input::get('name'), 'username' => Input::get('username'), 'email' => Input::get('email'), 'password' => Hash::make(Input::get('password'), $salt), 'salt' => $salt, 'joined' => date('Y-m-d H:i:s'), 'group' => 1)); Session::flash('success', 'Welcome, <b>' . Input::get('username') . '</b>!<br>Your account has been registered. You may now log in.'); Redirect::to('login.php'); } catch (Exception $e) { echo $error, '<br>'; } } else { foreach ($validate->errors() as $error) { $errors .= '<div class="bs-component" style="padding: "><div class="alert alert-dismissable alert-danger"><button type="button" class="close" data-dismiss="alert">×</button>' . $error . '</div></div>'; } } } }
} $forum = new Forum(); if (!isset($_GET["tid"]) || !is_numeric($_GET["tid"])) { Redirect::to('/forum/error/?error=not_exist'); die; } else { $topic_id = $_GET["tid"]; $forum_id = $queries->getWhere('topics', array('id', '=', $topic_id)); $forum_id = $forum_id[0]->forum_id; } if ($user->canViewMCP($user->data()->id)) { // TODO: Change to permission based if statement if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('merge' => array('required' => true))); $posts_to_move = $queries->getWhere('posts', array('topic_id', '=', $topic_id)); if ($validation->passed()) { try { foreach ($posts_to_move as $post_to_move) { $queries->update('posts', $post_to_move->id, array('topic_id' => Input::get('merge'))); } $queries->delete('topics', array('id', '=', $topic_id)); // Update latest posts in categories $forum->updateForumLatestPosts(); $forum->updateTopicLatestPosts(); Redirect::to('/forum/view_topic/?tid=' . Input::get('merge')); die; } catch (Exception $e) { die($e->getMessage()); }
include 'includes/overall/header.php'; /** * auf dieser seit kann der user sein passwort ändern */ $user = new User(); //wenn der user nicht eingeloggt ist, hat er hier nicht verloren, daher weiterleiten auf index if (!$user->isLoggedIn()) { Redirect::to('index.php'); } if (Input::exists()) { //token beim user muss mit token auf sever übereinstimmen if (Token::check(Input::get('token'))) { $validate = new Validate(); //die neuen passwörter werden validiert $validation = $validate->check($_POST, array('password_current' => array('required' => true), 'password_new' => array('required' => true, 'min' => 6), 'password_new_again' => array('required' => true, 'min' => 6, 'matches' => 'password_new'))); //validierung war erfolgreich if ($validation->passed()) { //altes password mit dem password in der datenbank verglichen if (password_verify(Input::get('password_current'), $user->data()->password)) { //wenn auch das stimmt, kann das neue passwort in die datenbank gespeichert werden $user->update(array('password' => Hash::make(Input::get('password_new')))); //der user wird auf index weitergeleitet, dort wird die message angezeigt, dass sein pw aktualisiert wurde Session::flash('home', 'Your password has been changed'); Redirect::to('index.php'); } else { //falls es zu einem problem beim aktualisieren der db kommt, wird eine meldung ausgegeben echo 'Your current password is wrong'; } } else { //falls die validierung nicht erfolgreich war, werden die errors ausgegeben
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(-1); //require_once("../functions/functions.php"); require_once "DB.php"; require_once "Hash.php"; require_once "Alert.php"; require_once "Validate.php"; //All login and register password checking and validation logic goes here $validate = new Validate(); $type = $_POST['type']; if ($type == 'log') { $info = array('passed' => false, 'content' => ''); $validation = $validate->check($_POST, array('email' => array('required' => true), 'password' => array('required' => true))); if ($validation->passed()) { if ($validation->login_correct()) { $info['passed'] = true; //$info ['content']=Alert::correct_signup(); } else { $info['content'] = Alert::return_error_div($validation->returnErrors()); } } else { $info['content'] = Alert::return_error_div($validation->returnErrors()); } echo $info['content']; // echo php_encode($info); } else { if ($type == 'sign') { $validation = $validate->check($_POST, array('first_name' => array('required' => true), 'last_name' => array('required' => true), 'email' => array('required' => true, 'unique' => 'email', 'format' => 'email'), 'password' => array('required' => true, 'min' => 6)));
<?php require_once '../core/init.php'; $page = new Page(); $page->setTitle('Test'); $page->startBody(); ?> <!-- BODY CONTENT --> <?php if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('username' => array('displayName' => 'Username', 'required' => true, 'min' => 2, 'max' => 20, 'unique' => 'users'), 'password' => array('displayName' => 'Password', 'required' => true, 'min' => 6), 'password_again' => array('displayName' => 'Repeat password', 'required' => true, 'matches' => 'password'), 'name' => array('displayName' => 'Full name', 'required' => true, 'min' => 2, 'max' => 50))); if ($validation->passed()) { $user = new User(); $salt = Hash::salt(32); try { $user->create(array('username' => Input::get('username'), 'password' => Hash::make(Input::get('password'), $salt), 'salt' => $salt, 'name' => Input::get('name'), 'joined' => date('Y-m-d H:i:s'), 'group' => 1)); Session::flash('home', 'You have been registered and can now login!'); Redirect::to('index.php'); } catch (Exception $e) { die($e->getMessage()); } } else { foreach ($validation->errors() as $error) { echo $error, '<br>'; } } } }