How to secure database passwords in PHP? Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Most of the websites are providing sing up and login facility to the user. User has to create a password and use it for login to the website. But it is very important to secure the password of the user. password_hash() function provides the facility to securely store the password of the user to the database. Syntax password_hash(Password, PASSWORD_DEFAULT) Example: First parameter Password will contain the normal password. The second Parameter will contain PASSWORD_BCRYPT to make secure otherwise it contains PASSWORD_DEFAULT as default. Let's see the example to understand properly. dbconn.php php <?php $db_host = "localhost"; $db_name = "secure_pass"; $db_pass = ""; $db_user = "root"; $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name); if (!$conn){ die ('Failed to connect with server'); } ?> Signup Form: html <form action="index.php" method="POST"> <label for="username">Username</label> <input type="text" name="username" required><br><br> <label for="password">Password</label> <input type="password" name="password" required><br><br> <input type="submit" name="submit" value="submit"> </form> index.php php <?php //Include database connection file include 'dbconn.php'; if (isset($_POST['submit'])){ $username = $_POST['username']; // Normal Password $pass = $_POST['password']; // Securing password using password_hash $secure_pass = password_hash($pass, PASSWORD_BCRYPT); $sql = "INSERT INTO login_tb (u_username, u_password) VALUES('$username', '$secure_pass')"; $result = mysqli_query($conn, $sql); } // Include HTML sign up form include 'signup_form.php'; ?> Output:Password In Database. Comment More infoAdvertise with us Next Article How to match username and password in database in SQL ? A akashmoradiya3444 Follow Improve Article Tags : Web Technologies PHP Write From Home PHP-Misc Similar Reads How to match username and password in database in SQL ? In this article, we are going to check the credentials (username and password) entered by the user. If credentials are matched from the database entries, the user can enter into another page and if credentials are incorrect then it displays "Sorry Invalid Username and Password". Pre-requisites: XAMP 4 min read How to Hide Password in HTML ? Hiding the password is commonly known as Password Masking. It hides the password characters when entered by the users by the use of bullets (â¢), an asterisk (*), or some other characters. It is always a good practice to use password masking to ensure security and avoid misuse. Generally, password ma 2 min read How to store password securely in your local/custom database in Node.js ? The custom database signifies the local database in your file system. There are two types of database 'SQL' and 'NoSQL'. In SQL database data are stored as table manner and in Nosql database data are stored independently with some particular way to identify each record independently. We can also cre 4 min read How to fetch data from the database in PHP ? Database operations in PHP are a very crucial thing that is especially needed in CRUD (Create, Read, Update and Delete) operations. In this article, we will discuss the Read part i.e. data fetching from database. There are two ways to connect to a database using PHP. They are as follows. MySQLi ("i" 4 min read How To Password Protect A Google Form Google Forms is an incredibly versatile tool for gathering information, conducting surveys, and planning events. However, when dealing with sensitive data, it's crucial to ensure that your forms are secure and accessible only to intended respondents. By setting up a simple but effective security lay 4 min read How to Update Data in MySQL Database Table Using PHP? Updating data in a MySQL database table using PHP is a fundamental aspect of web development, particularly in applications where user interactions involve modifying existing records. This guide delves into the process of updating data in a MySQL database table using PHP, covering database connection 3 min read Like