当前位置: 首页>>代码示例>>PHP>>正文


PHP salt函数代码示例

本文整理汇总了PHP中salt函数的典型用法代码示例。如果您正苦于以下问题:PHP salt函数的具体用法?PHP salt怎么用?PHP salt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了salt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: vInsertIntoOwnerLoginTable

function vInsertIntoOwnerLoginTable($SafeFirstName, $SafeLastName, $SafeEmail, $SafePWD)
{
    global $mysqli;
    $UserID = $SafeFirstName . $SafeLastName;
    $iOwnerExists = iCheckIfOwnerEmailExists($SafeEmail);
    #if this is the first claim.
    if ($iOwnerExists == 0) {
        #Obtain a cryption and save it in the DB.
        $salt = salt();
        #Hash a string that is comprised of password and a salt.
        #Save it as a password.  This will create a second level of security.
        $hash = getHash($SafePWD, $salt);
        # The folloing is for email activation of validation.
        $email_code = md5($SafeEmail + microtime());
        if (DEBUG) {
            echo "salt =" . $salt . "<br>";
            echo "SafePWD =" . $SafePWD . "<br>";
            echo "hash =" . $hash . "<br>";
        }
        #user_id is also email address.
        $mysqli->autocommit(FALSE);
        $InsertCommand = "INSERT INTO \r\n                                  login_table ( id, user_id, salt, password, email_address, email_code, type )\r\n\t\t\t\t  values ( NULL, '" . $SafeEmail . "', '" . $salt . "', '" . $hash . "', '" . $SafeEmail . "', '" . $email_code . "', 'O' )";
        $add_post_res = $mysqli->query($InsertCommand);
        # or die($mysqli->error);
        if (!$mysqli->commit()) {
            $mysqli->rollback();
        }
        SendActivateEmailNotice($SafeEmail, $email_code);
        echo "Please activate your email to complete the registration.  Please respond to your email. Thanks.";
    } else {
        /*popup( "You have already registere!", OWNER_LOGIN_PAGE ); */
        echo "You have already registered!";
    }
}
开发者ID:nguaki,项目名称:baboom,代码行数:34,代码来源:owner_register.php

示例2: encrypt

function encrypt($string)
{
    $crypt = '';
    $salt1 = salt(21);
    $salt2 = salt(rand(20, 23));
    switch (rand(1, 5)) {
        case 1:
            $crypt = crypt1($string);
            break;
        case 2:
            $crypt = crypt2($string);
            break;
        case 3:
            $crypt = crypt3($string);
            break;
        case 4:
            $crypt = crypt4($string);
            break;
        case 5:
            $crypt = crypt4($string);
            break;
    }
    $crypt = $salt1 . $crypt . $salt2;
    return base64_encode($crypt);
}
开发者ID:JaredClayborn,项目名称:hitNoMore,代码行数:25,代码来源:encrypt.php

示例3: create

 public function create($username, $email, $password, $sendConfirmation = true, $group = USER_GROUP_DEFAULT_SIGNUP)
 {
     global $sDB, $sTemplate;
     $salt = salt();
     $passwordHash = crypt($password, '$6$rounds=5000$' . $salt . '$');
     $dateAdded = time();
     $sDB->execUsers("INSERT INTO `users` (`userId`, `userName`, `email`, `group`, `password`, `salt`, `dateAdded`) VALUES\n                                             (NULL, '" . mysql_real_escape_string($username) . "', '" . mysql_real_escape_string($email) . "', '" . i($group) . "', '" . mysql_real_escape_string($passwordHash) . "', '" . mysql_real_escape_string($salt) . "', '" . i($dateAdded) . "');");
     if (mysql_affected_rows()) {
         $this->userId = mysql_insert_id();
         $this->userName = $username;
         $this->email = $email;
         $this->password = $passwordHash;
         $this->salt = $salt;
         $this->dateAdded = $dateAdded;
         $this->group = $group;
         if ($sendConfirmation) {
             $confirmationCode = md5(time());
             $confirmationLink = $sTemplate->getRoot() . "confirmation.php?userId=" . $this->userId . "&confirmationCode=" . $confirmationCode;
             $this->addConfirmationCode("CONFIRMATION_TYPE_EMAIL", $confirmationCode);
             $subject = $sTemplate->getString("SIGNUP_CONFIRMATION_EMAIL_SUBJECT");
             $message = $sTemplate->getString("SIGNUP_CONFIRMATION_EMAIL_BODY", array("[USERNAME]", "[PASSWORD]", "[CONFIRMATION_LINK]"), array($this->userName, $password, $confirmationLink));
             $mail = new HTMLMail($this->email, $this->email, SENDMAIL_FROM_NAME, SENDMAIL_FROM);
             $mail->buildMessage($subject, $message);
             $mail->sendmail();
         }
         return true;
     } else {
         return false;
     }
 }
开发者ID:PiratenparteiHessen,项目名称:wikiarguments,代码行数:30,代码来源:user.php

示例4: genrandom

function genrandom($len, $salt = null)
{
    if (empty($salt)) {
        $salt = salt('a', 'z') . salt('A', 'Z') . salt('0', '9');
    }
    $str = "";
    for ($i = 0; $i < $len; $i++) {
        $index = rand(0, strlen($salt) - 1);
        $str .= $salt[$index];
    }
    return $str;
}
开发者ID:port80labs,项目名称:Boxmeup,代码行数:12,代码来源:gen-security.php

示例5: m_login

function m_login($user, $password)
{
    $link = newdb();
    $stmt = $link->prepare("SELECT salt,password FROM players WHERE player=?");
    $stmt->bind_param('s', $user);
    $stmt->execute();
    $stmt->bind_result($salt, $password2);
    if (!$stmt->fetch()) {
        return FALSE;
    }
    if (salt($salt, $password) == $password2) {
        return TRUE;
    }
    return FALSE;
}
开发者ID:betrok,项目名称:minecraft-master,代码行数:15,代码来源:functions.php

示例6: add

 public function add()
 {
     if ($_POST) {
         $this->form_validation->set_rules('first_name', 'First Name', 'trim|required|max_length[12]');
         $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|max_length[24]');
         $this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
         $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]|matches[confirm_password]');
         $this->form_validation->set_rules('confirm_password', 'Confirm Password', 'required');
         $this->form_validation->set_rules('phone', 'Phone', 'required');
         $this->form_validation->set_rules('mobile', 'Mobile', 'required');
         $this->form_validation->set_rules('company', 'Company', 'required');
         $this->form_validation->set_rules('position', 'Position', 'required');
         $this->form_validation->set_message('is_unique', 'The %s is already exist');
         if ($this->_data['type'] == 'superadmin') {
             $this->form_validation->set_rules('type', 'Type', 'required');
         }
         if ($this->form_validation->run()) {
             $info['first_name'] = $_POST['first_name'];
             $info['last_name'] = $_POST['last_name'];
             $info['email'] = $_POST['email'];
             $info['salt'] = $salt = salt();
             $info['password'] = hashPassword($_POST['password'], $salt);
             $info['phone'] = $_POST['phone'];
             $info['mobile'] = $_POST['mobile'];
             $info['company'] = $_POST['company'];
             $info['position'] = $_POST['position'];
             if ($this->_data['type'] == 'superadmin') {
                 $info['type'] = $_POST['type'];
             } else {
                 $info['type'] = 'user';
             }
             $new_user_id = $this->user_model->newUser($info);
             $details['user_id'] = $new_user_id;
             $details['field'] = 'creator_id';
             $details['value'] = $this->session->userdata('user_id');
             $this->db->insert('user_details', $details);
             //$this->_send_email($info);
             redirect('user/user');
         }
     }
     $this->_data['breadcrumb'] = 'user/add_user';
     $this->_data['page_title'] = "Create User";
     $this->_data['companyList'] = $this->user_model->companyList();
     $this->_data['view'] = 'user_add';
     $this->load->view('user/home', $this->_data);
 }
开发者ID:Al-Amin-Ceazer,项目名称:comac-codeigniter,代码行数:46,代码来源:user.php

示例7: crypt_apr_md5

function crypt_apr_md5($plain, $salt = null)
{
    if (is_null($salt)) {
        $salt = salt(8);
    } elseif (preg_match('/^\\$apr1\\$/', $salt)) {
        $salt = preg_replace('/^\\$apr1\\$([^$]+)\\$.*/', '\\1', $salt);
    } else {
        $salt = substr($salt, 0, 8);
    }
    $length = strlen($plain);
    $context = $plain . '$apr1$' . $salt;
    $binary = hex2bin(md5($plain . $salt . $plain));
    for ($i = $length; $i > 0; $i -= 16) {
        $context .= substr($binary, 0, $i > 16 ? 16 : $i);
    }
    for ($i = $length; $i > 0; $i >>= 1) {
        $context .= $i & 1 ? chr(0) : $plain[0];
    }
    $binary = hex2bin(md5($context));
    for ($i = 0; $i < 1000; $i++) {
        $new = $i & 1 ? $plain : substr($binary, 0, 16);
        if ($i % 3) {
            $new .= $salt;
        }
        if ($i % 7) {
            $new .= $plain;
        }
        $new .= $i & 1 ? substr($binary, 0, 16) : $plain;
        $binary = hex2bin(md5($new));
    }
    $p = array();
    for ($i = 0; $i < 5; $i++) {
        $k = $i + 6;
        $j = $i + 12;
        if ($j == 16) {
            $j = 5;
        }
        $p[] = to64(ord($binary[$i]) << 16 | ord($binary[$k]) << 8 | ord($binary[$j]), 5);
    }
    return '$apr1$' . $salt . '$' . implode($p) . to64(ord($binary[11]), 3);
}
开发者ID:huluwa,项目名称:zz_atmailopen,代码行数:41,代码来源:aprpwd.inc.php

示例8: authenticate

 public function authenticate(array $options = array())
 {
     $app = \App::getInstance();
     if (!isset($options['username']) && !isset($options['password'])) {
         return null;
     }
     $userCollection = \Norm\Norm::factory(@$this->options['userCollection'] ?: 'User');
     $user = $userCollection->findOne(array('!or' => array(array('username' => $options['username']), array('email' => $options['username']), array('normalized_username' => str_replace('.', '', $options['username'])))));
     if (function_exists('salt')) {
         $options['password'] = salt($options['password']);
     }
     if (is_null($user) || $user['password'] . '' !== $options['password']) {
         return null;
     }
     if (empty($options['keep'])) {
         $app->session->reset();
     } else {
         $app->session->reset(array('lifetime' => 365 * 24 * 60 * 60));
     }
     $_SESSION['user'] = $user->toArray();
     return $user->toArray();
 }
开发者ID:reekoheek,项目名称:bono-auth,代码行数:22,代码来源:NormAuth.php

示例9: vInsertIntoClientLoginTable

function vInsertIntoClientLoginTable($SafeFirstName, $SafeLastName, $SafeEmail, $SafePWD)
{
    global $mysqli;
    $UserID = $SafeFirstName . $SafeLastName;
    $iClientExists = iCheckIfClientEmailExists($SafeEmail);
    #if this is the first claim.
    if ($iClientExists == 0) {
        $salt = salt();
        $hash = getHash($SafePWD, $salt);
        $email_code = md5($SafeEmail + microtime());
        #user_id is also email address.
        $mysqli->autocommit(FALSE);
        $InsertCommand = "INSERT INTO client_login_table \r\n                                        ( id, first_name, last_name, email_address, email_code, salt, password )\r\n                                  values \r\n                                  (NULL,'{$SafeFirstName}', '{$SafeLastName}', '{$SafeEmail}', '{$email_code}', '{$salt}', '{$hash}' )";
        $add_post_res = $mysqli->query($InsertCommand) or die($mysqli->error);
        if (!$mysqli->commit()) {
            $mysqli->rollback();
        }
        SendActivateEmailNotice($SafeEmail, $email_code);
        echo "Please activate your email to complete the registration.  Please respond to your email. Thanks.";
    } else {
        /*popup('You have already registered.', "http://" . IP_ADDRESS . "/member/client_login_register.php");*/
        echo "You have already registered";
    }
}
开发者ID:nguaki,项目名称:baboom,代码行数:24,代码来源:member_register.php

示例10: edit_email_send_mail

 /**
  * 发送邮件给新的邮箱地址
  * @param User   $user
  * @param string $email
  * @param string $password
  * @throws \Exception
  */
 public function edit_email_send_mail($user, $email, $password)
 {
     lib()->load('UserCheck', 'MailTemplate');
     $email = strtolower(trim($email));
     if ($user->getPassword() !== UserCheck::CreatePassword($password, $user->getSalt())) {
         $this->throwMsg(-10);
     }
     $email_check = UserCheck::CheckEmail($email);
     if ($email_check !== true) {
         throw new \Exception($email_check);
     }
     $meta = ['edit_email_add' => $email, 'edit_email_time' => date("Y-m-d H:i:s"), 'edit_email_code' => salt_hash($email . $user->getEmail(), salt())];
     $user->getMeta()->set($meta);
     $mt = new MailTemplate("edit_email.html");
     $mt->setUserInfo($user->getInfo());
     $mt->setValues(['verify_code' => $meta['edit_email_code']]);
     $mt->mailSend($user->getName(), $email);
 }
开发者ID:ttym7993,项目名称:Linger,代码行数:25,代码来源:UserControl.php

示例11: edit_pwd

 public function edit_pwd($old, $new)
 {
     $this->db = db_class();
     switch ($this->login_type) {
         case "admin":
             $info = $this->db->get_admin_info($this->user_info['name']);
             if (salt_hash(md5_xx($old), $info['a_salt']) != $info['a_pwd']) {
                 return "原密码错误";
             }
             $update = ['a_salt' => salt(32)];
             $update['a_pwd'] = salt_hash(md5_xx($new), $update['a_salt']);
             if ($this->db->update_user_info($this->user_info['name'], $update) == 1) {
                 return true;
             }
             break;
         case "teacher":
             $info = $this->db->get_teacher_info_by_id($this->user_info['it_id']);
             if ($info['it_password'] != $old) {
                 return "原密码错误";
             }
             if ($this->db->base_info_edit("info_teacher", ['it_password' => $new], ['it_id' => $info['it_id']]) == 1) {
                 return true;
             }
             break;
             break;
         case "student":
             $info = $this->db->get_student_info_by_id($this->user_info['is_id']);
             if ($info['is_password'] != $old) {
                 return "原密码错误";
             }
             if ($this->db->base_info_edit("info_student", ['is_password' => $new], ['is_id' => $info['is_id']]) == 1) {
                 return true;
             }
             break;
     }
     return "修改密码失败";
 }
开发者ID:dalinhuang,项目名称:StudentManage,代码行数:37,代码来源:Login.php

示例12: CreateActivationUrl

 /**
  * @param $user \ULib\User
  * @throws \Exception
  * @return mixed
  */
 private function CreateActivationUrl(&$user)
 {
     $code = md5(salt(64) . $user->getId());
     $user->getMeta()->set(["activation_code" => $code, "activation_time" => date("Y-m-d H:i:s")]);
     return hook()->apply("UserRegister_CreateActivationUrl", get_url("User", "activation", $code), $code, $user);
 }
开发者ID:ttym7993,项目名称:Linger,代码行数:11,代码来源:UserRegister.php

示例13: form_input

if (isset($_POST['gender'])) {
    $gender = form_input($_POST["gender"]);
}
if (!in_array($gender, array(0, 1, -1, 2))) {
    throwJSON(array("status" => "error", "code" => 305, "msg" => "feild gender out of range."));
    exit;
}
//密码
if (isset($_POST['password'])) {
    $password = form_input($_POST["password"]);
}
if (isNull($password)) {
    throwJSON(array("status" => "error", "code" => 306, "msg" => "password can not be null"));
    exit;
}
$salt = salt(6);
//随机撒盐
$newpass = md5(md5($password) . $salt);
//验证码
if (isset($_POST['captcha'])) {
    $captcha = form_input($_POST["captcha"]);
}
if (isNull($captcha)) {
    throwJSON(array("status" => "error", "code" => 307, "msg" => "captcha can not be null"));
    exit;
} else {
    /*
    $expire   = $_SESSION["captcha"]["expire"];
    $time1    = $_SESSION["captcha"]["createtime"];
    $captcha1 = $_SESSION["captcha"]["code"];
    if($tim1+$expire>$now){ //验证码是否过期
开发者ID:xudong7930,项目名称:mobile,代码行数:31,代码来源:signup.php

示例14: mysqli_query

<?php

@session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$usertype = $_POST['usertype'];
$dept = $_POST['dept'];
include 'dbconnect.php';
$result = mysqli_query($con, "SELECT * FROM users");
$flag = true;
while ($row = mysqli_fetch_array($result)) {
    if ($row['username'] == $username) {
        $flag = false;
    }
}
include 'salt.php';
$salt = salt(8);
$passhashed = md5(md5($password) . md5($salt));
$lastlogin = date('Y-m-d H:i:s');
if ($flag == true) {
    $result = mysqli_query($con, "INSERT INTO users (username, salt, password, usertype, dept, lastlogin)\r\nVALUES ('{$username}','{$salt}','{$passhashed}','{$usertype}','{$dept}','{$lastlogin}')");
    $_SESSION['error'] = "user_created";
    header('location: ./adduser.php');
} else {
    $_SESSION['error'] = "user_exist";
    header('location: ./adduser.php');
}
开发者ID:rohitjangid,项目名称:cognizance_department_tool,代码行数:27,代码来源:adduser_request.php

示例15: resetpassword

 function resetpassword($username, $password)
 {
     @session_start();
     $salt = salt(8);
     $user = userdetails($username);
     if (count($user) == 1) {
         $salt = $user[0]["salt"];
         $pass = md5($salt . md5($password));
         $con = dbconnect();
         mysqli_query($con, "INSERT INTO users (password) VALUES ('{$password}')");
         $_SESSION['success'] = "Password reset";
         // header("location: resetpassword.php");
     } else {
         $_SESSION['error'] = "Invalid Username";
         // header("location: resetpassword.php");
     }
 }
开发者ID:rohitjangid,项目名称:cognizance_registration_tool,代码行数:17,代码来源:include.php


注:本文中的salt函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。