本文整理汇总了PHP中encryptPassword函数的典型用法代码示例。如果您正苦于以下问题:PHP encryptPassword函数的具体用法?PHP encryptPassword怎么用?PHP encryptPassword使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encryptPassword函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addNewUser
function addNewUser()
{
// globals
global $DB;
global $MySelf;
global $MB_EMAIL;
// Sanitize the input.
$USERNAME = $MySelf->getUsername;
$NEW_USER = strtolower(sanitize($_POST[username]));
// supplied new username.
if (!ctypeAlnum($NEW_USER)) {
makeNotice("Only characters a-z, A-Z and 0-9 are allowed as username.", "error", "Invalid Username");
}
/* Password busines */
if ($_POST[pass1] != $_POST[pass2]) {
makeNotice("The passwords did not match!", "warning", "Passwords invalid", "index.php?action=newuser", "[retry]");
}
$PASSWORD = encryptPassword("{$_POST['pass1']}");
$PASSWORD_ENC = $PASSWORD;
/* lets see if the users (that is logged in) has sufficient
* rights to create even the most basic miner. Level 3+ is
* needed.
*/
if (!$MySelf->canAddUser()) {
makeNotice("You are not authorized to do that!", "error", "Forbidden");
}
// Lets prevent adding multiple users with the same name.
if (userExists($NEW_USER) >= 1) {
makeNotice("User already exists!", "error", "Duplicate User", "index.php?action=newuser", "[Cancel]");
}
// So we have an email address?
if (empty($_POST[email])) {
// We dont!
makeNotice("You need to supply an email address!", "error", "Account not created");
} else {
// We do. Clean it.
$NEW_EMAIL = sanitize($_POST[email]);
}
// Inser the new user into the database!
$DB->query("insert into users (username, password, email, addedby, confirmed) " . "values (?, ?, ?, ?, ?)", array("{$NEW_USER}", "{$PASSWORD_ENC}", "{$NEW_EMAIL}", $MySelf->getUsername(), "1"));
// Were we successfull?
if ($DB->affectedRows() == 0) {
makeNotice("Could not create user!", "error");
} else {
// Write the user an email.
global $SITENAME;
$mail = getTemplate("newuser", "email");
$mail = str_replace('{{USERNAME}}', "{$NEW_USER}", $mail);
$mail = str_replace('{{PASSWORD}}', "{$PASSWORD}", $mail);
$mail = str_replace('{{SITE}}', "http://" . $_SERVER['HTTP_HOST'] . "/", $mail);
$mail = str_replace('{{CORP}}', "{$SITENAME}", $mail);
$mail = str_replace('{{CREATOR}}', "{$USERNAME}", $mail);
$to = $NEW_EMAIL;
$DOMAIN = $_SERVER['HTTP_HOST'];
$subject = "Welcome to MiningBuddy";
$headers = "From:" . $MB_EMAIL;
mail($to, $subject, $mail, $headers);
makeNotice("User added and confirmation email sent.", "notice", "Account created", "index.php?action=editusers");
}
}
示例2: addUser
function addUser($username, $email, $password, $avatar, $steamid)
{
//Check if user exists
$checkLogin = checkUserLogin($username);
if ($checkLogin == FALSE) {
//Loginname doesn't exist
//Check if email exists
$checkEmail = checkEmail($email);
if ($checkEmail == FALSE) {
//Email doesn't exist
$thisUser = new User();
$thisUser->username = $username;
$thisUser->loginname = $username;
$thisUser->password = encryptPassword($password);
$thisUser->email = $email;
$thisUser->avatar = $avatar;
$thisUser->steamid = $steamid;
$thisUser->save();
return TRUE;
} else {
//Email exists
return FALSE;
}
} else {
//Loginname exists
return FALSE;
}
}
示例3: registerUser
function registerUser()
{
$userName = $_POST['userName'];
# Verify that the user doesn't exist in the database
$result = verifyUser($userName);
if ($result['status'] == 'COMPLETE') {
$email = $_POST['email'];
$userFirstName = $_POST['userFirstName'];
$userLastName = $_POST['userLastName'];
$userPassword = encryptPassword();
# Make the insertion of the new user to the Database
$result = registerNewUser($userFirstName, $userLastName, $userName, $email, $userPassword);
# Verify that the insertion was successful
if ($result['status'] == 'COMPLETE') {
# Starting the session
startSession($userFirstName, $userLastName, $userName);
echo json_encode($result);
} else {
# Something went wrong while inserting the new user
die(json_encode($result));
}
} else {
# Username already exists
die(json_encode($result));
}
}
示例4: save
public function save()
{
global $IP_ADDRESS;
$returnVal = false;
if ($this->objSignUpForm->validate()) {
$newPassword = encryptPassword($_POST['password']);
$arrColumns = array("username", "password", "password2", "email", "applydate", "ipaddress");
$arrValues = array($_POST['username'], $newPassword['password'], $newPassword['salt'], $_POST['email'], time(), $IP_ADDRESS);
if ($this->addNew($arrColumns, $arrValues)) {
$result = $this->MySQL->query("SELECT appcomponent_id FROM " . $this->MySQL->get_tablePrefix() . "app_components ORDER BY ordernum DESC");
while ($row = $result->fetch_assoc()) {
$this->objAppComponent->select($row['appcomponent_id']);
$this->objAppComponent->saveAppValue($this->intTableKeyValue);
}
$returnVal = true;
$this->notifyManagers();
}
} else {
$_POST = filterArray($_POST);
if ($this->objSignUpForm->prefillValues) {
$this->objSignUpForm->prefillPostedValues();
}
$_POST['submit'] = false;
}
return $returnVal;
}
示例5: actionLogin
public function actionLogin($id = 0)
{
if (isset($_POST['password'])) {
$pw = $_POST['password'];
$id = (int) $_POST['server_id'];
$server = Server::model()->findByPk((int) $id);
if (!$server) {
throw new CHttpException(404, Yii::t('mc', 'The requested page does not exist.'));
}
$this->net2FtpDefines();
global $net2ftp_result, $net2ftp_settings, $net2ftp_globals;
require_once dirname(__FILE__) . '/../extensions/net2ftp/main.inc.php';
require_once dirname(__FILE__) . '/../extensions/net2ftp/includes/authorizations.inc.php';
$ftpSv = $this->getFtpServer($server);
if (strlen($pw)) {
$_SESSION['net2ftp_password_encrypted'] = encryptPassword($pw);
$sessKey = 'net2ftp_password_encrypted_' . $ftpSv['ip'] . $this->getUsername($server);
unset($_SESSION[$sessKey]);
}
Yii::log('Logging in to FTP server for server ' . $id);
$this->redirect(array('ftpClient/browse', 'id' => $id));
}
$ftpUser = FtpUser::model()->findByAttributes(array('name' => Yii::app()->user->name));
$daemons = array();
$serverList = array();
$sel = Yii::t('mc', 'Please select a server');
if ($ftpUser) {
$c = new CDbCriteria();
$c->join = 'join `ftp_user_server` on `t`.`id`=`server_id`';
$c->condition = '`user_id`=? and `perms`!=\'\'';
$c->params = array((int) $ftpUser->id);
$svs = Server::model()->findAll($c);
$serverList = array(0 => Yii::t('mc', 'Select'));
foreach ($svs as $sv) {
$dmn = Daemon::model()->findByPk($sv->daemon_id);
$dmnInfo = array('ip' => '', 'port' => '');
if (!$dmn) {
$dmnInfo['ip'] = Yii::t('mc', 'No daemon found for this server.');
} else {
if (isset($dmn->ftp_ip) && isset($dmn->ftp_port)) {
$dmnInfo = array('ip' => $dmn->ftp_ip, 'port' => $dmn->ftp_port);
} else {
$dmnInfo['ip'] = Yii::t('mc', 'Daemon database not up to date, please run the Multicraft installer.');
}
}
$daemons[$sv->id] = $dmnInfo;
$serverList[$sv->id] = $sv->name;
}
} else {
$serverList = array(0 => Yii::t('mc', 'No FTP account found'));
$sel = Yii::t('mc', 'See the "Users" menu of your server for a list of FTP accounts');
}
$this->render('login', array('id' => $id, 'havePw' => isset($_SESSION['net2ftp_password_encrypted']), 'serverList' => $serverList, 'daemons' => $daemons, 'sel' => $sel));
}
示例6: set_password
function set_password($new_password)
{
$returnVal = false;
if ($this->intTableKeyValue != "") {
$passwordInfo = encryptPassword($new_password);
if ($this->update(array("password", "password2"), array($passwordInfo['password'], $passwordInfo['salt']))) {
$returnVal = true;
}
}
return $returnVal;
}
示例7: execSignup
function execSignup($username, $password, $confirmpw, $firstname, $lastname, $gender)
{
if ($username == "" || !isValidUsername($username)) {
return "Username is empty or invalid!";
}
if ($password == "" || !isValidPassword($password)) {
return "Password is empty or invalid!";
}
if ($confirmpw == "" || !isValidPassword($confirmpw)) {
return "Confirm Password is empty or invalid!";
}
if ($firstname == "" || !isValidName($firstname)) {
return "First Name is empty or invalid!";
}
if ($lastname == "" || !isValidName($lastname)) {
return "Last Name is empty or invalid!";
}
if ($gender == "" || !isValidGender($gender)) {
return "Gender is empty or invalid!";
}
$userDAO = new UserDAO();
//verify username exist
$result = $userDAO->getUserByUsername($username);
if ($result !== null) {
return "Username exists, please change to another one!";
}
//verify $password == $confirmpw
if ($password != $confirmpw) {
return "Password and Confirm Password must be same!";
}
$roleDAO = new RoleDAO();
$role = $roleDAO->getRoleByID(3);
//normal user
$departmentDAO = new DepartmentDAO();
$depart = $departmentDAO->getDepartmentByID(1);
//root department
$encryptPW = encryptPassword($password);
$photoURL = "photo/default.png";
$user = new User($role, $depart, $username, $encryptPW, $firstname, $lastname, $gender, $photoURL);
if ($userDAO->insertUser($user) === true) {
return true;
} else {
return "Insert user into table error, please contact administrator!";
}
}
示例8: execChangePW
function execChangePW($password, $newpassword, $confirmpw)
{
if ($password == "" || $newpassword == "" || $confirmpw == "") {
return "Please fill all the necessary information!";
}
if (!isValidPassword($password) || !isValidPassword($newpassword)) {
return "Please enter a valid password!";
}
if ($newpassword !== $confirmpw) {
return "The new password and the confirmed new password must be the same!";
}
$userDAO = new UserDAO();
$user = $userDAO->getUserByID($_SESSION["userID"]);
if (!verifyPassword($password, $user->getPassword())) {
return "The old password you entered is not correct!";
}
$encryptPW = encryptPassword($newpassword);
$user->setPassword($encryptPW);
$userDAO->updateUser($user);
return true;
}
示例9: changePassword
function changePassword()
{
global $DB;
global $MySelf;
// sanitizing.
$username = sanitize($MySelf->getUsername());
// Are we allowed to change our password?
if (!$MySelf->canChangePwd()) {
makeNotice("You are not allowed to change your password. Ask your CEO to re-enable this feature for your account.", "error", "Forbidden");
}
// Passwords the very same?
if ("{$_POST['password1']}" != "{$_POST['password2']}") {
makeNotice("Your entered passwords do not match, please head back, and try again!", "error", "Password not changed", "index.php?action=changepw", "[retry]");
}
// Passwords empty?
if (empty($_POST[password1]) || empty($_POST[password2])) {
makeNotice("You need to enter passwords in both fields!!", "error", "Password missing!", "index.php?action=changepw", "[retry]");
}
/*
* At this point we know that the user who submited the
* password change form is both legit and the form was not tampered
* with. Proceed with the password-change.
*/
// encode both supplied passwords with crypt.
$password = encryptPassword("{$_POST['password1']}");
$oldpasswd = encryptPassword("{$_POST['password']}");
// Update the Database.
global $IS_DEMO;
if (!$IS_DEMO) {
$DB->query("update users set password = '{$password}' where username = '{$username}' and password ='{$oldpasswd}'");
if ($DB->affectedRows() == 1) {
makeNotice("Your password has been changed.", "notice", "Password change confirmed");
} else {
makeNotice("Your password could not have been changed! Database error!", "error", "Password change failed");
}
} else {
makeNotice("Your password would have been changed. (Operation canceled due to demo site restrictions.)", "notice", "Password change confirmed");
}
}
示例10: editPassword
function editPassword($idUser, $pass_given, $new_pass)
{
if ($pass_given === $new_pass) {
return false;
}
global $db;
$stmt = $db->prepare('SELECT password FROM User WHERE idUser = :idUser');
$stmt->bindParam(':idUser', $idUser, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll();
if (count($result) === 0) {
return false;
}
if (!decryptPassword($pass_given, $result[0]['password'])) {
return false;
}
$passEnc = encryptPassword($new_pass, 20);
$stmt = $db->prepare('UPDATE User SET password = :new_pass WHERE idUser = :idUser');
$stmt->bindParam(':idUser', $idUser, PDO::PARAM_STR);
$stmt->bindParam(':new_pass', $passEnc, PDO::PARAM_STR);
$stmt->execute();
return true;
}
示例11: login
/**
* @param $username
* @param $userpass
* @return bool|object
* Login.
*/
function login($username, $userpass)
{
if ($username == "" || $userpass == "") {
return false;
}
$salt = "";
$sql = "SELECT Salt, UserID FROM tbl_users WHERE Email = " . convertForInsert($username);
$mysqli = new mysqli(Database::dbserver, Database::dbuser, Database::dbpass, Database::dbname);
$rs = $mysqli->query($sql);
while ($row = $rs->fetch_assoc()) {
$userid = $row['UserID'];
$salt = $row['Salt'] == "" ? generateSalt($userid) : $row['Salt'];
}
$salted = encryptPassword($userpass, $salt);
$rs->free();
$mysqli->close();
$sql = "SELECT UserID, FirstName FROM tbl_users WHERE Email = " . convertForInsert($username) . " AND Password = " . convertForInsert($salted);
$mysqli = new mysqli(Database::dbserver, Database::dbuser, Database::dbpass, Database::dbname);
$rs = $mysqli->query($sql);
if ($rs->num_rows < 1) {
//we don't have this user
return false;
} else {
while ($row = $rs->fetch_assoc()) {
$data = array("success" => true, "usertoken" => generateToken($row['UserID']), "userfirstname" => $row['FirstName']);
return json_encode($data);
}
//return true;
}
}
示例12: editUser
function editUser()
{
// We need global variables and object.
global $DB;
global $MySelf;
global $IS_DEMO;
if ($IS_DEMO && $_POST[id] == "1") {
makeNotice("The user would have been changed. (Operation canceled due to demo site restrictions.)", "notice", "Password change confirmed");
}
// Are we allowed to Manage Users?
if (!$MySelf->canManageUser()) {
makeNotice("You are not allowed to edit Users!", "error", "forbidden");
}
// Sanitize the ID
$ID = sanitize($_POST[id]);
$SELF = $MySelf->getID();
if (!is_numeric($ID)) {
// Yikes! Non-Number!
makeNotice("Variable is not numeric! (in editUser)", "error");
}
// Load the dataset.
$userDS = $DB->query("SELECT * FROM users WHERE id='{$ID}' LIMIT 1");
$user = $userDS->fetchRow();
// Non-admin tries to edit an admin, err no.
if ($user[isAdmin] && !$MySelf->isAdmin()) {
makeNotice("Only an Administrator may edit another Administrator. You do have the rights to edit users, but you are not allowed to modify an Administrators account.", "warning", "Insufficient rights!", "index.php?action=edituser&id={$ID}", "Cancel");
}
// Do we want to delete the user?
if ($_POST[delete] == "true") {
if ($ID == $SELF) {
makeNotice("You can not delete yourself! Why would you do such a thing? " . "Life is not that bad, c'mon...'", "warning", "Operation canceled", "index.php?action=edituser&id={$ID}", "get yourself together, man");
}
// Are we allowed to delete users?
if (!$MySelf->canDeleteUser()) {
makeNotice("You are not authorized to do that!", "error", "Forbidden");
}
// Get confirmation
confirm("You are about to delete " . ucfirst(idToUsername($ID)) . ". Are you sure?");
$DB->query("UPDATE users SET deleted='1' WHERE id='{$ID}' LIMIT 1");
if ($DB->affectedRows() == 1) {
makeNotice("The Account has been deleted.", "notice", "Account deleted", "index.php?action=editusers", "Back to editing Users");
} else {
makeNotice("Error deleting the user!", "error");
}
}
// Activate the account, or disable it.
if ("{$_POST['canLogin']}" == "on") {
$DB->query("UPDATE users SET active='1' WHERE id ='{$ID}' LIMIT 1");
} else {
if ($ID == $SELF) {
makeNotice("You can not deactivate yourself!", "error", "Err..", "index.php?action=edituser&id={$ID}", "Back to yourself ;)");
} else {
$DB->query("UPDATE users SET active='0' WHERE id ='{$ID}'");
}
}
// Confirm the account.
if ("{$_POST['confirm']}" == "true") {
$DB->query("UPDATE users SET confirmed='1' WHERE id ='{$ID}' LIMIT 1");
lostPassword($user[username]);
$ADD = " Due to confirmation I have sent an email to the user with his password.";
}
// Force the users email to be valid.
if ("{$_POST['SetEmailValid']}" == "true") {
$DB->query("UPDATE users SET emailvalid='1' WHERE id ='{$ID}' LIMIT 1");
}
global $IS_DEMO;
if (!$IS_DEMO) {
// Set the new email.
if (!empty($_POST[email])) {
$email = sanitize("{$_POST['email']}");
$DB->query("UPDATE users SET email='{$email}' WHERE id ='{$ID}'");
}
// Set the new Password.
if (!empty($_POST[password])) {
$password = encryptPassword(sanitize("{$_POST['password']}"));
$DB->query("UPDATE users SET password='{$password}' WHERE id ='{$ID}'");
}
// Change (shudder) the username.
if ($_POST[username_check] == "true" && $_POST[username] != "") {
if ($MySelf->isAdmin() && $MySelf->canManageUser()) {
// Permissions OK.
$new_username = sanitize($_POST[username]);
// Check for previously assigned username
$count = $DB->getCol("SELECT COUNT(username) FROM users WHERE username='{$new_username}'");
if ($count[0] > 0) {
// Username exists already.
makeNotice("The new username \"{$new_username}\" already exists. Unable to complete operation.", "error", "Username exists!");
} else {
// Username free. Update DB.
$DB->query("UPDATE users SET username='" . $new_username . "' WHERE ID='" . $ID . "' LIMIT 1");
// Check for failure, not success.
if ($DB->affectedRows() != 1) {
// Something is wrong :(
makeNotice("DB Error: Internal Error: Unable to update the username.", "error", "Internal Error");
}
}
} else {
// Insufficient permissions
makeNotice("Inusfficient rights to change username.", "error", "Insufficient Rights");
}
//.........这里部分代码省略.........
示例13: dbCheckUser
function dbCheckUser(&$session, $user, $code)
{
global $session_user;
$session->trace(TC_Db1, 'dbCheckUser');
$uid = dbUserId($session, $user);
if (!$uid) {
$rc = 1;
} else {
$fields = dbSingleRecord($session, 'select id,code,rights,locked,theme,width,height,maxhits,postingsperpage,' . 'threadsperpage,startpage from ' . dbTable($session, "user") . ' where name="' . $user . '";');
if ($fields == null) {
$rc = 1;
} elseif ($fields[1] == '') {
$rc = 0;
} else {
$code = encryptPassword($session, $user, $code);
$rc = true || strcmp($code, $fields[1]) == 0 ? 0 : 2;
}
}
// $count != 0
switch ($rc) {
case 1:
$rc = "Nicht definiert: {$user}";
break;
case 2:
$rc = "Passwort nicht korrekt!";
break;
case 3:
$rc = "Benutzer gesperrt!";
break;
default:
$rc = '';
$session_user = $fields[0];
$session->setUserData($session_user, $user, $fields[2], $fields[4], $fields[5], $fields[6], $fields[7], $fields[8], $fields[9], $fields[10]);
$session->setMacros();
break;
}
return $rc;
}
示例14: select_from_table
$response = select_from_table('person', 'idPerson', $params);
//echo $response;
$response = json_decode($response, true);
if (!empty($response)) {
$id = $response[0]['idPerson'];
}
}
//If ID is not set, then exit with message
if (!isset($id)) {
echo "E-Mail {$email} does not exist";
}
//Create a random password
$password = generateRandomString('5');
echo $password;
//Hash the password provided
$hash = encryptPassword($password);
//Save new password for user
//If already exists, then update password and if not insert record
$params = array();
$response = null;
$params = add_where('idPerson', $id, $params);
$response = select_from_table('password', 'idPerson', $params);
//echo $response;
if (empty(json_decode($response, true))) {
//Insert
$record = array();
$records = array();
$record = add_field('idPerson', $id, $record);
$record = add_field('password', $hash, $record);
$record = add_field('misses', "0", $record);
$record = add_field('locked', "0", $record);
示例15: str_replace
$sContents = str_replace("#xmlUrl#", $sRayXmlUrl, $sContents);
$sContents = str_replace("#desktopUrl#", $sModulesUrl . $sModule . "/", $sContents);
break;
case 'userAuthorize':
$sResult = loginUser($sId, $sPassword);
$sContents = parseXml($aXmlTemplates['result'], $sResult == TRUE_VAL ? TRUE_VAL : "msgUserAuthenticationFailure");
if ($sResult == TRUE_VAL) {
$sContents .= parseXml($aXmlTemplates['status'], getUserStatus($sId));
$sContents .= getAvailableStatuses();
saveUsers(array('online' => array(), 'offline' => array()));
}
break;
case 'login':
$sContents = parseXml($aXmlTemplates['result'], "msgUserAuthenticationFailure", FAILED_VAL);
$sId = getIdByNick($sNick);
$sPassword = encryptPassword($sId, $sPassword);
if (loginUser($sNick, $sPassword, true) == TRUE_VAL) {
$aUserInfo = getUserInfo($sId);
login($sId, $sPassword);
$sContents = parseXml($aXmlTemplates['result'], $sId, SUCCESS_VAL, $sPassword);
}
break;
case 'logout':
logout($sId);
$sContents = parseXml($aXmlTemplates['result'], "", SUCCESS_VAL);
break;
case "getUsers":
$bInit = true;
case "updateUsers":
if (!isset($bInit)) {
$bInit = false;