Change password in php

oci_password_change

Изменяет пароль пользователя, указанного в username .

Функция oci_password_change() особенно полезна для скриптов PHP командной строки или при использовании непостоянных соединений во всем приложении PHP.

Список параметров

Идентификатор соединения, возвращаемый функцией oci_connect() или oci_pconnect() .

Возвращаемые значения

Если указан параметр database_name , oci_password_change() возвращает true в случае успешного выполнения или false в случае возникновения ошибки. Если указан параметр connection , oci_password_change() возвращает ресурс соединения в случае успешного выполнения или false в случае возникновения ошибки.

Примеры

Пример #1 Пример использования oci_password_change() с изменением пароля уже подключённого пользователя

$dbase = ‘localhost/orcl’ ;
$user = ‘cj’ ;
$current_pw = ‘welcome’ ;
$new_pw = ‘geelong’ ;

$c = oci_pconnect ( $user , $current_pw , $dbase );
oci_password_change ( $c , $user , $current_pw , $new_pw );
echo «Новый пароль : » . $new_pw . «\n» ;

Пример #2 Пример использования oci_password_change() с подключением и изменением пароля одновременно

$dbase = ‘localhost/orcl’ ;
$user = ‘cj’ ;
$current_pw = ‘welcome’ ;
$new_pw = ‘geelong’ ;

$c = oci_pconnect ( $user , $current_pw , $dbase );
if (! $c ) $m = oci_error ();
if ( $m [ ‘code’ ] == 28001 ) < // "ORA-28001: the password has expired"
// Подключение и сброс пароля одновременно
$c = oci_password_change ( $dbase , $user , $current_pw , $new_pw );
if ( $c ) echo «Новый пароль : » . $new_pw . «\n» ;
>
>
>

if (! $c ) < // Ошибка не совпадала с 28001, или не получилось изменить пароль
$m = oci_error ();
trigger_error ( ‘Не удалось подключиться к базе данных: ‘ . $m [ ‘message’ ], E_USER_ERROR );
>

// Использование подключения $c
// .

Примечания

Замечание:

Изменение пароля с помощью этой функции или непосредственно в Oracle должно выполняться аккуратно, поскольку PHP-приложение может продолжать использовать в постоянных соединениях данные аутентификации последнего удачного подключения, которые уже устарели. Наилучшим решением может быть перезапуск всех веб-серверов после смены пароля.

Замечание:

При обновлении библиотеки клиента Oracle или базы данных от версии установки до версии 11.2.0.3 и выше функция oci_password_change() может вернуть ошибку «ORA-1017: invalid username/password» (Неверные имя пользователя/пароль), если версии и клиента и сервера обновлены в одно время.

Замечание:

Второй набор параметров функции oci_password_change() доступен начиная с версии OCI8 1.1.

User Contributed Notes

  • OCI8 Функции
    • oci_​bind_​array_​by_​name
    • oci_​bind_​by_​name
    • oci_​cancel
    • oci_​client_​version
    • oci_​close
    • oci_​commit
    • oci_​connect
    • oci_​define_​by_​name
    • oci_​error
    • oci_​execute
    • oci_​fetch_​all
    • oci_​fetch_​array
    • oci_​fetch_​assoc
    • oci_​fetch_​object
    • oci_​fetch_​row
    • oci_​fetch
    • oci_​field_​is_​null
    • oci_​field_​name
    • oci_​field_​precision
    • oci_​field_​scale
    • oci_​field_​size
    • oci_​field_​type_​raw
    • oci_​field_​type
    • oci_​free_​descriptor
    • oci_​free_​statement
    • oci_​get_​implicit_​resultset
    • oci_​lob_​copy
    • oci_​lob_​is_​equal
    • oci_​new_​collection
    • oci_​new_​connect
    • oci_​new_​cursor
    • oci_​new_​descriptor
    • oci_​num_​fields
    • oci_​num_​rows
    • oci_​parse
    • oci_​password_​change
    • oci_​pconnect
    • oci_​register_​taf_​callback
    • oci_​result
    • oci_​rollback
    • oci_​server_​version
    • oci_​set_​action
    • oci_​set_​call_​timeout
    • oci_​set_​client_​identifier
    • oci_​set_​client_​info
    • oci_​set_​db_​operation
    • oci_​set_​edition
    • oci_​set_​module_​name
    • oci_​set_​prefetch_​lob
    • oci_​set_​prefetch
    • oci_​statement_​type
    • oci_​unregister_​taf_​callback

    Источник

    Change Password Code In PHP

    Hello friends, I am back with another new tutorial for you. Today we will learn you about how to make a change password code in php. Do you think it is very hard? No, its just simple. You have seen in many application about change password functionality. This functionality is very useful while user forgot its password or want to change its current password. So i will not waste your time and go to the point. Let’s start…

    Here we assume that we have one record in the database i.e. Email: [email protected], Password: abcd. Here password is stored in DB with password_hash() algorithm. Password_hash algorithm is consider as one of the best secure encryption algorithm. Remember that don’t use md5() encryption. md5() encryption is now not considered as a safest encryption.You can learn more about password_hash() and password_verify() from its official site.

    What logic should be used?

    Here we will use simple logic for change password code in PHP. In change password form, user will fill the information like old password, new password and confirm password. We will create a old password using password_verify function and match it with all email and password in database entries. Here you should remember that you have to store user’s email or userid in the session and use it for find out user who want to change its password. If we found any matched record then it will update their new password with password_hash encryption. We are not using email in this script but you can store it in session when user login and use it whenever needs.

    Now see the below practical code. So you can understand more.

    Create a change password html form with Javascript validation. Here is mine code. Please don’t copy it directly. First understand it and then practice it. If you have any problem while practice it then let me know in the comment box. I will help you to solve that problem.

    .form-table < width:350px; margin-left: auto; margin-right: auto; >label < font-weight: bold; >#form_submission_ajax < background-color: #eee; padding-top: 10px; padding-bottom: 10px; >.error < color: #ff0000; >input < border: 2px solid #531EBF; padding: 4px; >input[type=»submit»] < padding: 5px 15px; background-color: #531EBF; border: 2px solid #531EBF; color: #fff; border-radius: 5px; >h1
    », «new_password_error» => », «confirm_password_error» => » ]; $form_data = [ «old_password» => », «new_password» => », «confirm_password» => » ]; if(!empty($_SESSION[‘error’])) < $error = $_SESSION['error']; >if(!empty($_SESSION[‘form_data’])) < $form_data = $_SESSION['form_data']; >?>

    Change Password Form

    «> «> «>

    In the above form, there are three fields named old password, new password and confirm password. New password and current password will same. This form will validate using javascript before submit. So if user does not type confirm password same as new password then error established. Try that one 😉

    Now here is a code for change a password using PHP on the server. We have also validate form data on the server side.

    change-password.php

    [email protected]"; $valid = true; $error = []; $form_data = []; if(!empty($_POST['old_password'])) < $old_password = $_POST['old_password']; $old_password_data = array("old_password" =>$old_password); $form_data = array_merge($form_data, $old_password_data); $old_password_error = array("old_password_error" => ""); $error = array_merge($error, $old_password_error); > else < $valid = false; $old_password = ""; $old_password_data = array("old_password" =>$old_password); $form_data = array_merge($form_data, $old_password_data); $old_password_error = array("old_password_error" => "* Old password is required."); $error = array_merge($error, $old_password_error); > if(!empty($_POST['new_password'])) < $new_password = $_POST['new_password']; $new_password_data = array("new_password" =>$new_password); $form_data = array_merge($form_data, $new_password_data); $new_password_error = array("new_password_error" => ""); $error = array_merge($error, $new_password_error); > else < $valid = false; $new_password = ""; $new_password_data = array("new_password" =>$new_password); $form_data = array_merge($form_data, $new_password_data); $new_password_error = array("new_password_error" => "* New password is required."); $error = array_merge($error, $new_password_error); > if(!empty($_POST['confirm_password'])) < $confirm_password = $_POST['confirm_password']; $confirm_password_data = array("confirm_password" =>$confirm_password); $form_data = array_merge($form_data, $confirm_password_data); $confirm_password_error = array("confirm_password_error" => ""); $error = array_merge($error, $confirm_password_error); > else < $valid = false; $confirm_password = ""; $confirm_password_data = array("confirm_password" =>$confirm_password); $form_data = array_merge($form_data, $confirm_password_data); $confirm_password_error = array("confirm_password_error" => "* Confirm password is required."); $error = array_merge($error, $confirm_password_error); > if($new_password != '' && $confirm_password != '') < if($new_password != $confirm_password) < $valid = false; $confirm_password_error = array("confirm_password_error" =>"* Confirm password is same as new password."); $error = array_merge($error, $confirm_password_error); > if($new_password == $confirm_password) < $confirm_password_error = array("confirm_password_error" =>""); $error = array_merge($error, $confirm_password_error); > > if($valid==true) < include 'config.php'; mysqli_select_db($conn, $db_name); $check_data = "SELECT * FROM user_login WHERE email = '$email' "; $check_query = mysqli_query($conn, $check_data); $numRows = mysqli_num_rows($check_query); $user_data = mysqli_fetch_assoc($check_query); if($numRows == 1) < $check_old_password = password_verify($old_password,$user_data['password']); if($check_old_password) < $new_password_encrypt = password_hash($new_password,PASSWORD_DEFAULT); $user_id = $user_data['id']; $sql = "UPDATE user_login SET password = '$new_password_encrypt' WHERE "; $query = mysqli_query($conn, $sql); $row = mysqli_affected_rows($query); if($row == 1) < echo "Your password successfully changed."; die; >> else < echo "Opps, We can not find your data. Please try again."; die; >> else < echo "No database record matched with your data."; die; >> else < $_SESSION['error'] = $error; $_SESSION['form_data'] = $form_data; header('Location:index.php'); >?>

    All the data filled by user are on the server now. It’s time to validate them using php validation.
    In the change password script we use server side validation using PHP. If form data does not satisfy the validation condition then script will redirect to “index.php” with errors. Otherwise password will change in the database.

    I hope that you like this tutorial. Please share it with your friends. If you have any kind of problem regarding this tutorial then let me know in the comment box. I will help you to solve the problem. Thank you 🙂

    Источник

    How to change login password in PHP and MYSQL | Update user account password

    The password change operation is known as updating the user password during a session with the current password. We are creating a login and registration system from the scratch. In the previous tutorial, we had learned about user profile edit operation using the session. In this tutorial, we will create a password change form to update the user password using session-id(current session email Id). The password change operation is most important for a login system. It gives to ensures the security of the user which means users can change passwords anytime from their account. We are using bootstrap with PHP and MYSQL database. As you know, bootstrap is an HTML and CSS framework which is used to design websites using CSS classes and readymade modules. We will create a password change HTML form using bootstrap.

    Let’s discuss the process to change user password –

    Changing user password in PHP and MYSQL –

    In the password changing operation, we create three fields listed below —

    Current Password – The current password stands for the present time password that is used by the user to log in account. First of all, we will verify the current password. if the current password does not match then do not process more and if the current password match then processes for the password change operation (Password update operation using session-id ).
    New Password – Enter the new password.
    Confirm New Password – Re-enter the new password to confirm.
    In this user password update operation, we will use validation like – password length, password matches or not, password minimum, and maximum.

    We had created a password change button on account page in part 1. You can start learning from part 1.

    Let’s create a password change form with PHP code –

    change-password.php

     $email=$_SESSION["login_email"]; ?>       

    if($password != $passwordConfirm) < $error[] = 'Passwords do not match.'; >if(strlen($password) <5)< // min $error[] = 'The password is 6 characters long.'; >if(strlen($password)>20) < // Max $error[] = 'Password: Max length 20 Characters Not allowed'; >if(!isset($error)) < $options = array("cost"=>4); $password = password_hash($password,PASSWORD_BCRYPT,$options); $result = mysqli_query($dbc,"UPDATE users SET password='$password' WHERE email='$email'"); if($result) < header("location:account.php?password_updated=1"); >else < $error[]='Something went wrong'; >> > else < $error[]='Current password does not match.'; >> if(isset($error))< foreach($error as $error)< echo '

    '.$error.'

    '; > > ?>

    Logout

    We have created three text boxes for the current password, new password, and confirm password. These fields are important to change the password by the user after logging in.
    When a user clicks on the password change button the values from the three text boxes hold by the POST method.
    First of all, verify the current password in the database table where the current session email exists.
    After verifying the current password, the password gets validated and update through the update query using PHP and MYSQL.
    It’s a secure way to change passwords using PHP and MYSQL databases.
    In this way, users can change login password using session id.

    Источник

    Читайте также:  Image compression algorithms in java
Оцените статью