public function createToken() { $hash = sha1(microtime() . mt_rand() . "salty bastard"); $token = new Token(); $token->set('user_id', $this->id); $token->set('hash', $hash); $token->set('expire_date', date("Y-m-d H:i:s", strtotime("+1 year"))); $token->save(); return $token; }
data-ad-client="ca-pub-8066383283274201" data-ad-slot="3710749975"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <div class="chat_wrap"> <div class="toggle"> <h3>Chat</h3> </div> <div class="chat"> <header> <h3 class="toggle">Chat</h3> </header> <div class="chatArea"> <ul> <li><em>Loading...</em></li> </ul> </div> <form method="post"> <input type="text" name="chat_name" id="chat_name" maxlength="15" placeholder="Name" required> <input type="text" name="chat_message" id="chat_message" maxlength="140" placeholder="Message" required autocomplete="off"> <input type="hidden" name="chat_token" id="chat_token" value="<?php echo $token->set(); ?> "> </form> </div> </div> <script src="http://www.adam-bray.com/includes/script.js"></script> </body> </html>
function loginUser() { $data = Functions::getJSONData(); $nickname = Functions::elt($data, 'nickname'); $password = Functions::elt($data, 'password'); $expiration = Functions::elt($data, 'expiration'); $actionCount = Functions::elt($data, 'actionCount'); if (is_null($nickname) || is_null($password) || is_null($expiration) || is_null($actionCount)) { Functions::setResponse(400); } $whereClause = 'nickname = :nickname'; $params = array(array('id' => ':nickname', 'value' => $nickname)); $custList = Customer::search($whereClause, $params); if (!count($custList)) { Functions::setResponse(403); } $customer = $custList[0]; if (Functions::hash($password) == $customer->get('password')) { $t = new Token(); $t->set('customerId', $customer->get('id')); $t->set('value', Functions::randomHash()); $t->set('expiration', time() + floor($expiration / 1000)); $t->set('actionCount', $actionCount); $t->save(); return $t; } else { Functions::setResponse(403); } }
public function checkToken($champ, $addrMail) { $retour = true; $arch = new Archiviste(); $token = new Token(); $token->set($champ, $addrMail); $tokens = $arch->restituer($token); if (count($tokens) == 0) { $retour = false; } else { $retour = $tokens[0]; } return $retour; }