Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
PHP: mi primer sistema de inicio de sesión no verificará la contraseña

Probé mi primer sistema de inicio de sesión y cuelgué en la verificación de la contraseña.

La consulta para verificar si el usuario existe funciona, pero la verificación de la contraseña correcta no.

PHP:

 <?php $user = $_POST['namex']; $host = "localhost"; $username = "root"; $password = ""; $dbname = "mydb"; $db = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); $stmt = $db->prepare("SELECT * FROM accounts WHERE username = :s"); $stmt->bindParam(':s', $user); $stmt->execute(); $count = $stmt->rowCount(); if($count == 1) { $stmt2 = $db->prepare("SELECT password FROM accounts WHERE username =:s"); $stmt2->bindParam(':s', $user); $stmt2->bindParam(':pw', $upw); //here set the password from the database $inputpass = $_POST["pwx"]; //here set the input password if(password_verify($inputpass, $upw)){ //here try to check for the right input session_start(); $_SESSION["namex"] = $user; //here will start session for the input user echo "Youre logged in"; //header("Location:loggedin.php"); } else { echo "Password incorrect!"; } } else{ echo "This Account doesnt exists!"; } ?>

HTML:

 <form action="../login.php" method="post"> <div> <input class="Namebox" id="namex" name="namex" required placeholder="Benutzername"> <label for="namex" class="labelname"></label> </div> <div> <input type="password" class="pwbox" id="pwx" name="pwx" required placeholder="Passwort"> <label for="pwx" class="labelpw"></label> </div> <button class="login" type="submit" value="submit">Anmelden</button> </form>

Espero que alguien pueda ayudarme.

Saludos Kevin

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No necesita la segunda consulta sql, puede verificar la contraseña editando el código de la siguiente manera

 # ... $db = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); $stmt = $db->prepare("SELECT * FROM accounts WHERE username = :s"); $stmt->bindParam(':s', $user); $stmt->execute(); $count = $stmt->rowCount(); if($count == 1) { $user = $stmt->fetch(); $inputpass = $_POST["pwx"]; if(password_verify($inputpass, $user["password"])){ session_start(); # ...
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!