本文整理汇总了PHP中generate_hash函数的典型用法代码示例。如果您正苦于以下问题:PHP generate_hash函数的具体用法?PHP generate_hash怎么用?PHP generate_hash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate_hash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: OS_CaptchaOnRegistration
function OS_CaptchaOnRegistration()
{
if (isset($_SESSION["r_code"]) and $_SESSION["r_code"] == "OK") {
/* CAPTCHA OK */
} else {
$code = rand(100, 10000);
$_SESSION["r_code"] = $code;
$trap1 = generate_hash(16);
$trap2 = generate_hash(8);
$_SESSION["r_trap1"] = $trap1;
$_SESSION["r_trap2"] = $trap2;
?>
<tr>
<td class="padLeft">Captcha:</td>
<td class="padLeft">
<input type="text" size="1" value="" name="r_captcha"/>
<input type="hidden" name="<?php
echo $trap1;
?>
" value="<?php
echo $trap2;
?>
" />
<span style="font-size:26px; font-weight:bold;"><?php
echo $code;
?>
</span>
</td>
</tr>
<?php
}
}
示例2: check_login
function check_login(){
$user=db_easy("SELECT `name`, `password_hash` FROM `users` WHERE `name`='".mysql_real_escape_string(@$_POST['user'])."'");
if(generate_hash($user['name'], @$_POST['password'])==$user['password_hash']){
return true;
}else{
return false;
}
}
示例3: change_password
public function change_password(IChangePasswordInput $input)
{
// Prepare data
$this->load->helper('crypto');
$passwordsalt = generate_salt();
$passwordhash = generate_hash($input->get_password(), $passwordsalt);
$this->db->where('email', $input->get_email());
$this->db->where('passwordresetcode', $input->get_resetcode());
$this->db->update("users", array("passwordresetcode" => NULL, "passwordhash" => $passwordhash, "passwordsalt" => $passwordsalt));
return $this->db->affected_rows() > 0;
}
示例4: OS_CheckCaptcha
function OS_CheckCaptcha()
{
if (isset($_POST["post_comment"])) {
if (isset($_GET["post_id"]) and is_numeric($_GET["post_id"])) {
$backTo = OS_HOME . '?post_id=' . safeEscape($_GET["post_id"]) . "&" . generate_hash(12) . "#SubmitComment";
} else {
$backTo = '';
}
$CaptchaError = '<h2>Invalid captcha</h2><div><a href="' . $backTo . '">« Back</a></div>';
if (!isset($_POST["c_code"]) or !isset($_SESSION["c_code"])) {
os_trigger_error($CaptchaError);
}
if ($_POST["c_code"] != $_SESSION["c_code"]) {
os_trigger_error($CaptchaError . " ");
} else {
$code = generate_hash(5);
$code = str_replace(array("o", "0"), array("x", "x"), $code);
$_SESSION["c_code"] = $code;
}
}
}
示例5: login
function login($username, $password, $dbh)
{
if ($query = $dbh->prepare("SELECT uid, username, password FROM accounts WHERE username = ? LIMIT 1")) {
$query->bindValue(1, $username);
// Bind "$username" to parameter.
$query->execute();
// Execute the prepared query.
$result = $query->fetch();
$user_id = $result['uid'];
$username = $result['username'];
$storedpass = $result['password'];
$storedsalt = substr($storedpass, 0, 32);
// break salt from stored hash
$password = generate_hash($password, $storedsalt);
// hash the attempted password with the unique salt from database.
if ($result) {
// If the user exists
if ($storedpass == $password) {
// Check if the password in the database matches the password the user submitted.
// Password is correct!
$ip_address = $_SERVER['REMOTE_ADDR'];
// Get the IP address of the user.
$user_browser = $_SERVER['HTTP_USER_AGENT'];
// Get the user-agent string of the user.
$user_id = preg_replace("/[^0-9]+/", "", $user_id);
// XSS protection as we might print this value
$_SESSION['user_id'] = $user_id;
$username = preg_replace("/[^a-zA-Z0-9_\\-]+/", "", $username);
// XSS protection as we might print this value
$_SESSION['username'] = $username;
$_SESSION['login_string'] = hash('sha512', $password . $ip_address . $user_browser);
// Login successful.
return true;
}
}
} else {
// No user exists.
return false;
}
}
示例6: __construct
public function __construct($processed_array)
{
$this->entrada_url = isset($processed_array["entrada_url"]) ? $processed_array["entrada_url"] : "";
$this->entrada_relative = isset($processed_array["entrada_relative"]) ? $processed_array["entrada_relative"] : "";
$this->entrada_absolute = isset($processed_array["entrada_absolute"]) ? $processed_array["entrada_absolute"] : "";
$this->entrada_storage = isset($processed_array["entrada_storage"]) ? $processed_array["entrada_storage"] : "";
$this->database_adapter = isset($processed_array["database_adapter"]) ? $processed_array["database_adapter"] : "mysql";
$this->database_host = isset($processed_array["database_host"]) ? $processed_array["database_host"] : "";
$this->database_username = isset($processed_array["database_username"]) ? $processed_array["database_username"] : "";
$this->database_password = isset($processed_array["database_password"]) ? $processed_array["database_password"] : "";
$this->entrada_database = isset($processed_array["entrada_database"]) ? $processed_array["entrada_database"] : "";
$this->auth_database = isset($processed_array["auth_database"]) ? $processed_array["auth_database"] : "";
$this->clerkship_database = isset($processed_array["clerkship_database"]) ? $processed_array["clerkship_database"] : "";
$this->admin_username = isset($processed_array["admin_username"]) ? $processed_array["admin_username"] : "";
$this->admin_password_hash = isset($processed_array["admin_password_hash"]) ? $processed_array["admin_password_hash"] : "";
$this->admin_firstname = isset($processed_array["admin_firstname"]) ? $processed_array["admin_firstname"] : "";
$this->admin_lastname = isset($processed_array["admin_lastname"]) ? $processed_array["admin_lastname"] : "";
$this->admin_email = isset($processed_array["admin_email"]) ? $processed_array["admin_email"] : "";
$this->auth_username = isset($processed_array["auth_username"]) ? $processed_array["auth_username"] : generate_hash();
$this->auth_password = isset($processed_array["auth_password"]) ? $processed_array["auth_password"] : generate_hash();
$this->config_file_path = $this->entrada_absolute . "/core/config/config.inc.php";
}
示例7: create
/**
* Add new user
*
* @param array $user_data
*
* @return bool
*/
public function create($user_data)
{
$user_data = $this->validate($user_data);
if (!$user_data) {
return false;
}
$user_exist = $this->checkExist($user_data);
if ($user_exist) {
$this->setAttributes($user_exist);
return true;
}
$hash = generate_hash();
$date_start = date("Y-m-d H-i-s");
$sql = "INSERT INTO\n {$this->table_name} (\n name,\n email,\n phone,\n hash,\n date_start,\n conference_id\n ) VALUES (\n :name,\n :email,\n :phone,\n :hash,\n :date_start,\n :conference_id\n )";
$prepare_statement = $this->connection->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
$status = $prepare_statement->execute([':name' => $user_data['name'], ':email' => $user_data['email'], ':phone' => $user_data['phone'], ':conference_id' => $user_data['conference_id'], ':date_start' => $date_start, ':hash' => $hash]);
if (!$status) {
return false;
}
$user_data['hash'] = $hash;
$user_data['date_start'] = $date_start;
$this->setAttributes($user_data);
return true;
}
示例8: generate_hash
$TOTAL_ERRORS = $ERROR;
$STEP = 2;
}
case 2:
/**
* Keys to allow Entrada to access the authentication web-service.
*/
if (isset($_POST["auth_username"]) && ($auth_username = clean_input($_POST["auth_username"], "alphanumeric"))) {
$PROCESSED["auth_username"] = $auth_username;
} else {
$PROCESSED["auth_username"] = generate_hash();
}
if (isset($_POST["auth_password"]) && ($auth_password = clean_input($_POST["auth_password"], "alphanumeric"))) {
$PROCESSED["auth_password"] = $auth_password;
} else {
$PROCESSED["auth_password"] = generate_hash();
}
case 1:
default:
continue;
break;
}
$setup = new Entrada_Setup($PROCESSED);
/**
* Post-Error Check Data Processing
*/
switch ($STEP) {
case 6:
if (@file_exists($PROCESSED["entrada_absolute"] . "/.htaccess")) {
if (@file_exists($PROCESSED["entrada_absolute"] . "/core/config/config.inc.php")) {
try {
示例9: createUser
/**
* Creates a user account and updates object, returns true or false.
* $user_data requires: "username", "firstname", "lastname", "email", "password", "organisation_id"
* $user_access requires: "group", "role", "app_id"
*
* @param array $user_data User data array, keys match table fields. Ex: array("id" => "1", "username" => "foo").
* @param array $user_access User access array, keys match table fields. Ex: array("group" => "admin").
* @return boolean
*/
public function createUser(array $user_data, array $user_access)
{
global $db;
$required_user_data = array("username", "firstname", "lastname", "email", "password", "organisation_id");
$required_user_access = array("group", "role", "app_id");
foreach ($required_user_data as $data) {
if (!array_key_exists($data, $user_data)) {
$error = true;
}
}
foreach ($required_user_access as $data) {
if (!array_key_exists($data, $user_access)) {
$error = true;
}
}
if (!$error) {
foreach ($user_data as $fieldname => $data) {
$processed["user_data"][$fieldname] = clean_input($data, array("trim", "striptags"));
}
foreach ($user_access as $fieldname => $data) {
$processed["user_access"][$fieldname] = clean_input($data, array("trim", "striptags"));
}
if ($db->AutoExecute("`" . AUTH_DATABASE . "`.`user_data`", $processed["user_data"], "INSERT")) {
$processed["user_data"]["id"] = $db->Insert_ID();
$processed["user_access"]["user_id"] = $processed["user_data"]["id"];
if (!isset($processed["user_access"]["organisation_id"])) {
$processed["user_access"]["organisation_id"] = $processed["user_data"]["organisation_id"];
}
if (!isset($processed["user_access"]["access_starts"])) {
$processed["user_access"]["access_starts"] = time();
}
if (!isset($processed["user_access"]["account_active"])) {
$processed["user_access"]["account_active"] = "true";
}
if (!isset($processed["user_access"]["private_hash"])) {
$processed["user_access"]["private_hash"] = generate_hash();
}
if (!$db->AutoExecute("`" . AUTH_DATABASE . "`.`user_access`", $processed["user_access"], "INSERT")) {
application_log("error", "Failed to add user, DB said: " . $db->ErrorMsg());
$return = false;
} else {
$params = get_class_vars(__CLASS__);
foreach ($params as $param_name => $param) {
$this->{$param_name} = isset($processed["user_data"][$param_name]) ? $processed["user_data"][$param_name] : (isset($processed["user_access"][$param_name]) ? $processed["user_access"][$param_name] : $param);
}
$return = true;
}
} else {
application_log("error", "Failed to add user, DB said: " . $db->ErrorMsg());
$return = false;
}
} else {
$return = false;
}
return $return;
}
示例10: trim
$pw = trim($_POST["password"]);
$email = trim($_POST["email"]);
if (strlen($admin) <= 2 or strlen($pw) <= 2) {
$admin = "admin";
$pw = "admin";
$email = "admin@openstats.iz.rs";
?>
<div>Admin username or password have too few characters</div>
<div>Inserting default admin username and password</div>
<div><b>Admin username:</b> admin</div>
<div><b>Admin password:</b> admin</div>
<div> </div>
<div>Don't forget to change admin username and password via admin panel</div>
<?php
}
$hash = generate_hash(16, 1);
$pass = generate_password($pw, $hash);
$userLevel = 10;
// 10 - root admin, 9 - administrator
$sth = $dbh->prepare("INSERT INTO oh_users(user_name, user_password, password_hash, user_email, user_joined, user_level,user_ip, confirm, can_comment) VALUES('{$admin}', '{$pass}', '{$hash}', '{$email}', '" . time() . "', '" . $userLevel . "', '" . $_SERVER["REMOTE_ADDR"] . "', '', '1')");
$sth->execute();
$result = 1;
flush();
if ($result) {
?>
<div> </div>
<div><b>Admin successfully created.</b></div>
<div style="display:none;">Please delete <b>install.php</b>, <b>sql_data.sql</b> and <b>sql_heroes_items.sql</b> from install directory.</div>
<div style="display:none;">Please delete or rename <b>install/</b> folder.</div>
示例11: check_hash
function check_hash($proper, $check)
{
$len = strlen($proper);
$nhash = generate_hash($check, substr($proper, $len - SALT_LENGTH));
if ($proper == $nhash) {
return true;
}
return false;
}
示例12: header
<?php
if (!isset($website)) {
header('HTTP/1.1 404 Not Found');
die;
}
$code = generate_hash(8);
$_SESSION["code"] = $code;
if (isset($errors) and !empty($errors)) {
?>
<div><?php
echo $errors;
?>
</div>
<?php
}
?>
<a name="comments"></a><?php
if (isset($CommentsData) and !empty($CommentsData)) {
?>
<div class="comments" id="comments">
<h4><?php
echo $lang["comments"];
?>
(<?php
echo $CommentsData[0]["total_comments"];
?>
)</h4>
<div class="comments-content">
<div id="comment-holder">
<ol>
示例13: get_hash_thold_template
function get_hash_thold_template($id)
{
$hash = db_fetch_cell("SELECT hash FROM thold_template WHERE id={$id}");
if (preg_match("/[a-fA-F0-9]{32}/", $hash)) {
return $hash;
} else {
return generate_hash();
}
}
示例14: generate_hash
img/fb_connect.png" width="300" height="50" alt="FB CONNECT" /></a>
<div>Click on the button above to sign in with your FB account</div>
<div style="margin-top: 360px;"> </div>
</div>
</div>
</div>
</div>
</div>
<?php
}
if ($user and isset($email) and strlen($email) >= 5) {
$result = $db->query("SELECT * FROM users WHERE user_email = '" . $email . "' AND user_fbid = '" . $user . "' ");
if ($db->num_rows($result) <= 0) {
$pass = generate_hash(5);
$hash = generate_hash(12);
$password_db = generate_password($pass, $hash);
$avatar = 'https://graph.facebook.com/' . $user . '/picture?type=large';
$www = 'http://www.facebook.com/profile.php?id=' . $user . '';
if ($gender == "male") {
$gen = 1;
} else {
if ($gender == "female") {
$gen = 2;
} else {
$gen = 0;
}
}
$insert = $db->query("INSERT INTO users(user_name, user_fbid, user_password, password_hash, user_email, user_joined, user_level, user_last_login, user_ip, user_avatar, user_website, user_gender) \n\t VALUES('" . safeEscape($name) . "', '" . $user . "', '" . $password_db . "', '" . $hash . "', '" . safeEscape($email) . "', '" . (int) time() . "', '0', '" . (int) time() . "', '" . safeEscape($_SERVER["REMOTE_ADDR"]) . "', '" . strip_tags($avatar) . "', '" . $www . "', '" . $gen . "')");
$id = $db->get_insert_id();
$_SESSION["user_id"] = $id;
示例15: handleUser
/**
* Creates user data / user access records
* @global type $db
* @param type $member_ldap_data
* @return int $status
*/
private function handleUser($member_ldap_data)
{
global $db;
$number = str_replace("S", "", $member_ldap_data[LDAP_USER_QUERY_FIELD]);
$GRAD = date("Y", time()) + 4;
$user_id = "";
$query = "SELECT * FROM `" . AUTH_DATABASE . "`.`user_data` WHERE `number` = ?";
$result = $db->GetRow($query, array($number));
if (!$result) {
if (isset($member_ldap_data["sn"]) && isset($member_ldap_data["givenName"]) && $member_ldap_data["sn"] && $member_ldap_data["givenName"]) {
$names[0] = $member_ldap_data["givenName"];
$names[1] = $member_ldap_data["sn"];
} else {
$names = explode(" ", $member_ldap_data["cn"]);
}
$student = array("number" => $number, "username" => strtolower($member_ldap_data[LDAP_MEMBER_ATTR]), "password" => md5(generate_password(8)), "organisation_id" => $this->course["organisation_id"], "firstname" => trim($names[0]), "lastname" => trim($names[1]), "prefix" => "", "email" => isset($member_ldap_data["mail"]) ? $member_ldap_data["mail"] : strtolower($member_ldap_data[LDAP_MEMBER_ATTR]) . "@queensu.ca", "email_alt" => "", "email_updated" => time(), "telephone" => "", "fax" => "", "address" => "", "city" => DEFAULT_CITY, "postcode" => DEFAULT_POSTALCODE, "country" => "", "country_id" => DEFAULT_COUNTRY_ID, "province" => "", "province_id" => DEFAULT_PROVINCE_ID, "notes" => "", "privacy_level" => "0", "notifications" => "0", "entry_year" => date("Y", time()), "grad_year" => $GRAD, "gender" => "0", "clinical" => "0", "updated_date" => time(), "updated_by" => "1");
if ($db->AutoExecute("`" . AUTH_DATABASE . "`.`user_data`", $student, "INSERT")) {
$user_id = $db->Insert_ID();
$access = array("user_id" => $user_id, "app_id" => $this->app_id, "organisation_id" => $this->course["organisation_id"], "account_active" => "true", "access_starts" => time(), "access_expires" => "0", "last_login" => "0", "last_ip" => "", "role" => $GRAD, "group" => "student", "extras" => "", "private_hash" => generate_hash(32), "notes" => "");
if ($db->AutoExecute("`" . AUTH_DATABASE . "`.`user_access`", $access, "INSERT")) {
application_log("error", "Failed to create user access record, DB said: " . $db->ErrorMsg());
}
} else {
application_log("error", "Failed to create user data record, DB said: " . $db->ErrorMsg());
}
} else {
$user_id = $result["id"];
$query = "SELECT * FROM `" . AUTH_DATABASE . "`.`user_access`\n WHERE `user_id` = " . $db->qstr($result["id"]) . " AND `organisation_id` = " . $db->qstr($this->course["organisation_id"]);
$access_record = $db->GetRow($query);
if (!$access_record) {
$access = array("user_id" => $user_id, "app_id" => $this->app_id, "organisation_id" => $this->course["organisation_id"], "account_active" => "true", "access_starts" => time(), "access_expires" => "0", "last_login" => "0", "last_ip" => "", "role" => $GRAD, "group" => "student", "extras" => "", "private_hash" => generate_hash(32), "notes" => "");
if (!$db->AutoExecute("`" . AUTH_DATABASE . "`.`user_access`", $access, "INSERT")) {
application_log("error", "Failed to create user access record, DB said: " . $db->ErrorMsg());
}
}
}
$query = "SELECT * FROM `group_members` \n WHERE `proxy_id` = " . $db->qstr($user_id) . "\n AND `group_id` = " . $db->qstr($this->group_id);
$group_member = $db->GetRow($query);
if (!$group_member) {
$values = array("group_id" => $this->group_id, "proxy_id" => $user_id, "start_date" => $this->course["start_date"], "expire_date" => $this->course["end_date"], "member_active" => "1", "entrada_only" => "0", "updated_date" => time(), "updated_by" => "1");
if (!$db->AutoExecute("group_members", $values, "INSERT")) {
application_log("error", "User was not added to group_members table, DB said: " . $db->ErrorMsg());
}
}
if ($this->community_id) {
$query = "SELECT * FROM `community_members` WHERE `proxy_id` = ? AND `community_id` = ?";
$community_membership = $db->GetRow($query, array($user_id, $this->community_id));
if (!$community_membership) {
$values = array("community_id" => $this->community_id, "proxy_id" => $user_id, "member_active" => "1", "member_joined" => time(), "member_acl" => "0");
if (!$db->AutoExecute("`community_members`", $values, "INSERT")) {
application_log("error", "Failed to add user to community, DB said: " . $db->ErrorMsg());
}
}
}
unset($this->community_audience[$user_id]);
}