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


PHP getSalt函数代码示例

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


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

示例1: getSalt

 protected function getSalt()
 {
     if (isset($_POST['password'])) {
         return getSalt();
     } else {
         return false;
     }
 }
开发者ID:yunsite,项目名称:nuomituan,代码行数:8,代码来源:UserModel.class.php

示例2: getPasswordHash

function getPasswordHash($id, $password, $fixedsalt)
{
    $salt = getSalt($id, $fixedsalt);
    $hash = '';
    //ストレッチング
    for ($i = 0; $i < 1000; $i++) {
        $hash = hash('sha256', $hash . $password . $salt);
    }
    return $hash;
}
开发者ID:soutaito,项目名称:IMIDataConverter,代码行数:10,代码来源:utility.php

示例3: set_address

function set_address($id, $address)
{
    #Sets address of user with id
    $id = mysql_real_escape_string($id);
    $address = mysql_real_escape_string($address);
    global $aes_password;
    $salt = getSalt($id);
    $ret = true;
    $query = "UPDATE users SET enc_address = AES_ENCRYPT('{$address}', '{$aes_password}{$salt}') WHERE id = {$id}";
    mysql_query($query) or $ret = false;
    return $ret;
}
开发者ID:henrikssn,项目名称:OpenPool,代码行数:12,代码来源:db.php

示例4: changePassword

 function changePassword($username, $newPassword)
 {
     $userArray = [];
     include "getUsersFromJSON.php";
     if (!empty($userArray)) {
         for ($i = 0; $i < sizeof($userArray); $i++) {
             if ($userArray[$i]->{'username'} == $username) {
                 $userArray[$i]->{'password'} = crypt($newPassword, getSalt());
                 break;
             }
         }
         $path_config_users = "";
         include "paths.php";
         file_put_contents($path_config_users, json_encode($userArray, JSON_PRETTY_PRINT));
     }
 }
开发者ID:DeadSpaghetti,项目名称:codera,代码行数:16,代码来源:functions.php

示例5: passwd

function passwd($oldpwd, $newpwd)
{
    global $session;
    global $dbh;
    if (!valid_passwd($oldpwd) || !valid_user($session['user'], $oldpwd, $privilege)) {
        echo "&error 3";
        return;
    }
    if (valid_passwd($newpwd)) {
        $query = sprintf("UPDATE users SET pass=%s WHERE user=%s", $dbh->quote(crypt($newpwd, getSalt())), $dbh->quote($session['user']));
        if ($dbh->exec($query) == 1) {
            echo "&end";
            return;
        } else {
            echo "&error 5";
        }
    } else {
        echo "&error 4";
    }
}
开发者ID:scovit,项目名称:nust-helico,代码行数:20,代码来源:user.php

示例6: login

 public function login()
 {
     //Gather data from AJAX
     $data = json_decode(file_get_contents('php://input'), true);
     $return['error'] = -3;
     $return['value'] = null;
     //Sanitise inputs
     $result = $this->checkInput($data, array('username', 'password'));
     if ($result == '') {
         //Check if UID exists
         $uid = getUserUID($data['username']);
         if ($uid == null) {
             $return['error'] = -2;
             $return['value'] = "Invalid credentials";
         } else {
             $saltedPw = crypt($data['password'], getSalt($data['username']));
             if (checkSaltedPass($data['username'], $saltedPw)) {
                 //Generates salt for username
                 $salt = $this->generateSalt();
                 //Authenticated token
                 $token = $data['username'] . $salt;
                 //Authentication information
                 $cookievars['username'] = $data['username'];
                 $cookievars['salt'] = $salt;
                 //Creates cookie with name of authenticated token,
                 setcookie(user_encrypt($token), json_encode($cookievars), 0, "/");
                 //Returns with authenticated token
                 $return['error'] = 0;
                 $return['value'] = user_encrypt($token);
             } else {
                 $return['error'] = -2;
                 $return['value'] = "Invalid credentials";
             }
         }
     } else {
         $return['error'] = -1;
         $return['value'] = $result;
     }
     $jsonstring = json_encode($return);
     echo $jsonstring;
 }
开发者ID:tonyward,项目名称:Teameet,代码行数:41,代码来源:accounts.php

示例7: overrideUserProperties

function overrideUserProperties($username, $password, $forbiddenProjects, $accountType, $newUsername)
{
    $userArray = [];
    include "getUsersFromJSON.php";
    $path_config_users = "";
    include "paths.php";
    if (!empty($userArray)) {
        for ($i = 0; $i < sizeof($userArray); $i++) {
            if ($userArray[$i]->{'username'} == $username) {
                if ($username != "admin" && $username != "public") {
                    if ($username == "New User" && $newUsername != "admin" && $newUsername != "public") {
                        $username = $newUsername;
                    }
                    if (isset($newUsername) && $newUsername != "admin" && $newUsername != "public") {
                        $username = $newUsername;
                    }
                    $userArray[$i]->{'username'} = $username;
                    $userArray[$i]->{'forbiddenProjects'} = $forbiddenProjects;
                    $userArray[$i]->{'accountType'} = $accountType;
                } elseif ($username == "public") {
                    $userArray[$i]->{'username'} = "public";
                    $userArray[$i]->{'forbiddenProjects'} = $forbiddenProjects;
                    $userArray[$i]->{'accountType'} = "user";
                } elseif ($username == "admin") {
                    $userArray[$i]->{'username'} = "admin";
                    $userArray[$i]->{'accountType'} = "admin";
                    $userArray[$i]->{'forbiddenProjects'} = "[]";
                }
                if (isset($password) && $password != "" && !is_null($password) && $username != "public") {
                    $userArray[$i]->{'password'} = crypt($password, getSalt());
                }
                include_once "functions.php";
                file_put_contents($path_config_users, json_encode(getSortedUserArray($userArray), JSON_PRETTY_PRINT));
                break;
            }
        }
    }
}
开发者ID:DeadSpaghetti,项目名称:codera,代码行数:38,代码来源:addUserToJSON.php

示例8: password

function password($pass)
{
    // following CakePHP hash method
    return sha1(getSalt() . $pass);
}
开发者ID:ivanbautsita,项目名称:gestion-escolar-campus-virtuales,代码行数:5,代码来源:config.php

示例9: crypt

    $userArray = [];
    include "getUsersFromJSON.php";
    for ($i = 0; $i < sizeof($userArray); $i++) {
        if ($userArray[$i]->{'username'} == $username) {
            if ($userArray[$i]->{'password'} == $password) {
                $_SESSION['loggedIn'] = $username;
                $returnValue = $userArray[$i]->{'accountType'};
            } else {
                //wrong password --> returnValue doesn't need to be changed!
            }
            break;
        }
    }
    echo $returnValue;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $username = $_POST['username'];
    $password = $_POST['password'];
    if (isset($username) && isset($password) && $username != "" && $password != "") {
        include_once "functions.php";
        $password = crypt($password, getSalt());
        if (file_exists($path_config_users)) {
            checkLoginData($username, $password);
        } else {
            echo 'failure';
            //file doesn't exist
        }
    } else {
        echo "wrongInput";
    }
}
开发者ID:DeadSpaghetti,项目名称:codera,代码行数:31,代码来源:checkLogin.php

示例10: mysqli_connect

					</form>
					
					<?php 
if (isset($_POST['username']) && isset($_POST['g-recaptcha-response'])) {
    if (isValid()) {
        if (strlen($_POST['username']) >= 8) {
            if (strlen($_POST['phone']) == countDigits($_POST['phone'])) {
                $con = mysqli_connect("localhost", "root", "PASS", "secure_login");
                if (mysqli_connect_errno()) {
                    die('Could not connect: ' . mysqli_connect_error());
                }
                $result = mysqli_query($con, "SELECT username FROM members WHERE username='" . $_POST['username'] . "'");
                if (mysqli_num_rows($result) == 0) {
                    $result = mysqli_query($con, "SELECT email FROM members WHERE email='" . strtolower($_POST['email']) . "'");
                    if (mysqli_num_rows($result) == 0) {
                        mysqli_query($con, "INSERT INTO members (username, password, email, phone, salt, recoveryid, recoveryValid) VALUES ('" . $_POST['username'] . "','" . strtoupper(getSalt()) . "','" . strtolower($_POST['email']) . "','" . $_POST['phone'] . "','" . strtoupper(getSalt()) . "','" . generateRandomString(16) . "','" . date("d/m/Y") . "')");
                        send_mail();
                        mysqli_close($con);
                        $pieces = explode("@", $_POST['email']);
                        echo "Thank you for your registration. <br/>";
                        echo "Please check <a href=\"" . $pieces[1] . "\">your email</a> to activate your account.";
                    } else {
                        echo "There is already an account associated with this email. <a href=\"index.php\">Login</a>";
                    }
                } else {
                    echo "This username is already in use. Please try another username.";
                }
            } else {
                echo 'The entered phone number does not seem to be valid. Please check it and try again. ([0-9])';
            }
        } else {
开发者ID:CodeSurfing145,项目名称:Wallet-Finder,代码行数:31,代码来源:register.php

示例11: getCryptedPassword

function getCryptedPassword($plaintext, $salt = '', $encryption = 'md5-hex', $show_encrypt = false)
{
    // Get the salt to use.
    $salt = getSalt($encryption, $salt, $plaintext);
    // Encrypt the password.
    switch ($encryption) {
        case 'plain':
            return $plaintext;
        case 'sha':
            $encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext));
            return $show_encrypt ? '{SHA}' . $encrypted : $encrypted;
        case 'crypt':
        case 'crypt-des':
        case 'crypt-md5':
        case 'crypt-blowfish':
            return ($show_encrypt ? '{crypt}' : '') . crypt($plaintext, $salt);
        case 'md5-base64':
            $encrypted = base64_encode(mhash(MHASH_MD5, $plaintext));
            return $show_encrypt ? '{MD5}' . $encrypted : $encrypted;
        case 'ssha':
            $encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext . $salt) . $salt);
            return $show_encrypt ? '{SSHA}' . $encrypted : $encrypted;
        case 'smd5':
            $encrypted = base64_encode(mhash(MHASH_MD5, $plaintext . $salt) . $salt);
            return $show_encrypt ? '{SMD5}' . $encrypted : $encrypted;
        case 'aprmd5':
            $length = strlen($plaintext);
            $context = $plaintext . '$apr1$' . $salt;
            $binary = JUserHelper::_bin(md5($plaintext . $salt . $plaintext));
            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) : $plaintext[0];
            }
            $binary = JUserHelper::_bin(md5($context));
            for ($i = 0; $i < 1000; $i++) {
                $new = $i & 1 ? $plaintext : substr($binary, 0, 16);
                if ($i % 3) {
                    $new .= $salt;
                }
                if ($i % 7) {
                    $new .= $plaintext;
                }
                $new .= $i & 1 ? substr($binary, 0, 16) : $plaintext;
                $binary = JUserHelper::_bin(md5($new));
            }
            $p = array();
            for ($i = 0; $i < 5; $i++) {
                $k = $i + 6;
                $j = $i + 12;
                if ($j == 16) {
                    $j = 5;
                }
                $p[] = JUserHelper::_toAPRMD5(ord($binary[$i]) << 16 | ord($binary[$k]) << 8 | ord($binary[$j]), 5);
            }
            return '$apr1$' . $salt . '$' . implode('', $p) . JUserHelper::_toAPRMD5(ord($binary[11]), 3);
        case 'md5-hex':
        default:
            $encrypted = $salt ? md5($plaintext . $salt) : md5($plaintext);
            return $show_encrypt ? '{MD5}' . $encrypted : $encrypted;
    }
}
开发者ID:nuthankumarns,项目名称:Edulab-web-services,代码行数:63,代码来源:account.php

示例12: ini_set

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
include 'functions.php';
if (isset($_GET['email']) && isset($_GET['password'])) {
    $con = mysqli_connect("localhost", "root", "PASS", "secure_login");
    if (mysqli_connect_errno()) {
        die('Could not connect: ' . mysqli_connect_error());
    }
    $result = mysqli_query($con, "SELECT email FROM members WHERE email='" . strtolower($_GET['email']) . "'");
    if (mysqli_num_rows($result) != 0) {
        $result = mysqli_fetch_assoc(mysqli_query($con, "SELECT * FROM members WHERE email='" . strtolower($_GET['email']) . "'"));
        if (strtoupper(hash('sha512', $_GET['password'] . $result['salt'])) == $result['password']) {
            $_SESSION['login'] = getSalt();
            $_SESSION['loginTime'] = date('H:i:s');
            $_SESSION['loginDate'] = date('Y/m/d ');
            $_SESSION['email'] = $_GET['email'];
            $_SESSION['username'] = $result['username'];
            $_SESSION['phone'] = $result['phone'];
            mysqli_query($con, "DELETE FROM `sessions` WHERE `sessions`.`email` = '" . strtolower($_GET['email']) . "'");
            mysqli_query($con, "INSERT INTO sessions (email, sessionId, loginTime, loginDate) VALUES ('" . strtolower($_GET['email']) . "', '" . $_SESSION['login'] . "', '" . $_SESSION['loginTime'] . "', '" . $_SESSION['loginDate'] . "')");
            if (check_login() == 0) {
                echo 'LOGIN_SUCCESS<br />' . $_SESSION['login'] . '<br />' . $_SESSION['username'] . '<br />' . $_SESSION['email'] . '<br />' . $_SESSION['phone'];
            } else {
                if (check_login() == 1) {
                    echo 'ERROR_EXPIRED';
                    session_destroy();
                }
            }
开发者ID:CodeSurfing145,项目名称:Wallet-Finder,代码行数:30,代码来源:index_mobile.php

示例13: session_start

<?php

if (!isset($_SESSION)) {
    session_start();
}
include_once "functions.php";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $oldPassword = $_POST['oldPassword'];
    $username = $_SESSION['loggedIn'];
    $password = $_POST['password'];
    if (isUserAdmin($username) || isset($oldPassword) && crypt($oldPassword, getSalt()) == getPassword($username)) {
        include_once "functions.php";
        changePassword($username, $password);
    } else {
        echo "denied";
    }
}
开发者ID:DeadSpaghetti,项目名称:codera,代码行数:17,代码来源:changeUserPassword.php

示例14: checkCookies

function checkCookies(&$forceLogin, &$error, $ignoreBlanks)
{
    $forceLogin = TRUE;
    $error = "";
    global $sessionDuration;
    dbgSquirt("==============Function: checkCoookies ==============");
    dbgSquirt('Cookie --' . dbgShowFile($_COOKIE));
    if (isset($_COOKIE['user']) && !empty($_COOKIE['user']) && isset($_COOKIE['authentication']) && !empty($_COOKIE['authentication'])) {
        // both user and authentication cookies are set and non-blank
        // dbgSquirt("Cookies set and non-empty");
        $userCookie = $_COOKIE['user'];
        $authenticationCookie = $_COOKIE['authentication'];
        $time = time();
        // dbgSquirt("Getting salt");
        if (getSalt($salt)) {
            // dbgSquirt("...salt gotten");
            // dbgSquirt("Encrypting");
            if (sha1($userCookie . $salt) == $authenticationCookie) {
                // authentication passed
                // so reset expiration on cookies
                // dbgSquirt("Cookie matches encryption");
                // dbgSquirt("Resetting cookies");
                // dbgSquirt("Time -- $time");
                // dbgSquirt("Time + Duration -- ". ($time+$sessionDuration));
                $result = setcookie("user", $userCookie, $time + $sessionDuration);
                $result1 = setcookie("authentication", $authenticationCookie, $time + $sessionDuration);
                if (TRUE == $result && TRUE == $result1) {
                    // everything worked
                    // dbgSquirt("Everything worked ... no need to forceLogin");
                    $forceLogin = FALSE;
                } else {
                    $error = "Internal error -- problem while creating cookies.  Please contact an administrator.";
                }
            } else {
                // credentials in cookies don't match.
                // dbgSquirt("Cookie does NOT match encryption");
                $error = "Authentication error -- The supplied credentials don't match our stored values. Please reauthenticate and try again.";
            }
        } else {
            // dbgSquirt("...error while getting salt");
            // error while trying to get salt value
            $error = "Internal error -- unable to validate supplied credentials. Please reauthenticate and try again.";
        }
    } else {
        // cookies were unset or contained empty values
        // dbgSquirt("Cookies unset or empty");
        if (FALSE == $ignoreBlanks) {
            $error = "Please log in.";
        }
    }
    dbgSquirt("Returning -- " . empty($error));
    return empty($error);
}
开发者ID:runamedia,项目名称:resiprocate,代码行数:53,代码来源:reprofunctions.php

示例15: getHashedPassword

 public function getHashedPassword($userName, $password)
 {
     $salt = getSalt($userName);
     $passwordHashed = crypt($password, $salt);
     return substr($passwordHashed, strlen($salt));
 }
开发者ID:Amfys,项目名称:BST,代码行数:6,代码来源:db.php


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