ProgrammingAnyone here decent at PHP?Posted:

Status: Offline
Joined: Jan 25, 20161 Year Member
Posts: 108
Reputation Power: 11
So I have an issue with this think I downloaded and it uses php. So basically you have to sign in using a login but theres no login provided, so I was wondering if there was a way to make it check if the username is like admin and password is password?
If that makes any sense.
Thanks
#2. Posted:
Xaldin
  • 2 Million
Status: Offline
Joined: Oct 09, 20107 Year Member
Posts: 2,251
Reputation Power: 101
If youre trying to use something like phpmyadmin it would be "root" for username and blank for pass until you change it/add your account.

Let us know what thing you are using and we can help
#3. Posted:
Status: Offline
Joined: Jan 25, 20161 Year Member
Posts: 108
Reputation Power: 11
Its not like that its a control panel for this thing and it uses a mysql data based which I have access to and the php file that runs the code.

So i was wondering if I can edit that code so it doesn't go to the database it just looks for it in the file e.g

if $username = "admin"
then bla bla

I can also provide the code via pm
#4. Posted:
Ryzen
  • Gold Member
Status: Offline
Joined: May 16, 2017
Posts: 174
Reputation Power: 52
Yeah, here's an example..

<?php
// Start a session
session_start();

// Correct details to login
$usernameCorrect = "admin";
$passwordCorrect = "admin123";

// Check on submission
if(isset($_POST['submit'])) {
    // Make it simpler on us for later use
   // It'd be smart to clean the input, but since I don't know
   // if you're using MySQL or PDO, or MySQLi I'll let you do that
   $usernameInput = $_POST['username'];
   $passwordInput = $_POST['password'];
   
   // Check if matches what we want
   if($usernameInput != $usernameCorrect) {
      // It matches so do whatever with it
   } else {
      // It does not match so maybe show them an error
   }
}
?>
<form method="post">
    <input name="username" type="text" placeholder="Username..">
   <input name="password" type="text" placeholder="Password..">
   <input name="submit" type="button" value="Submit">
</form>
#5. Posted:
Ryzen
  • Gold Member
Status: Offline
Joined: May 16, 2017
Posts: 174
Reputation Power: 52
Noticed I goofed up on my last post..
<?php
// Start a session
session_start();

// Correct details to login
$usernameCorrect = "admin";
$passwordCorrect = "admin123";

// Check on submission
if(isset($_POST['submit'])) {
    // Make it simpler on us for later use
   // It'd be smart to clean the input, but since I don't know
   // if you're using MySQL or PDO, or MySQLi I'll let you do that
   $usernameInput = $_POST['username'];
   $passwordInput = $_POST['password'];
   
   // Check if matches what we want
   if($usernameInput != $usernameCorrect || $passwordInput != $passwordCorrect) {
      // It matches so do whatever with it
   } else {
      // It does not match so maybe show them an error
   }
}
?>
<form method="post">
    <input name="username" type="text" placeholder="Username..">
   <input name="password" type="text" placeholder="Password..">
   <input name="submit" type="button" value="Submit">
</form>



Forgot to check if the password was right.. Oops!
#6. Posted:
ip
  • 2 Million
Status: Offline
Joined: Dec 30, 20124 Year Member
Posts: 3,697
Reputation Power: 423
Are you talking about PHPMyAdmin?
https://i.imgur.com/iLkRJws.png

You shouldn't have to create a form, you would have to edit the config files in order to allow people access depending on how you have it set up on a server or your local machine.
#7. Posted:
-Deano
  • Rated Awesome
Status: Offline
Joined: Aug 19, 20107 Year Member
Posts: 4,862
Reputation Power: 422
Motto: PCMR | Thanks to Jay for the gold!
Ryzen wroteNoticed I goofed up on my last post..
<?php
// Start a session
session_start();

// Correct details to login
$usernameCorrect = "admin";
$passwordCorrect = "admin123";

// Check on submission
if(isset($_POST['submit'])) {
    // Make it simpler on us for later use
   // It'd be smart to clean the input, but since I don't know
   // if you're using MySQL or PDO, or MySQLi I'll let you do that
   $usernameInput = $_POST['username'];
   $passwordInput = $_POST['password'];
   
   // Check if matches what we want
   if($usernameInput != $usernameCorrect || $passwordInput != $passwordCorrect) {
      // It matches so do whatever with it
   } else {
      // It does not match so maybe show them an error
   }
}
?>
<form method="post">
    <input name="username" type="text" placeholder="Username..">
   <input name="password" type="text" placeholder="Password..">
   <input name="submit" type="button" value="Submit">
</form>



Forgot to check if the password was right.. Oops!


You dun goofed again.

Should be like this
if($usernameInput == $usernameCorrect && $passwordInput == $passwordCorrect) {


You need to have == instead of != for your logic. Also, using " || " is a boolean OR, you need to use &&.
(Or you would just need to swap round your 'Correct' code block with the 'Incorrect' code block.

You aren't actually using the session variable so there's no need to update your session.
#8. Posted:
Ryzen
  • Gold Member
Status: Offline
Joined: May 16, 2017
Posts: 174
Reputation Power: 52
Eh, my bad again. It works fine I just had my comments in the wrong spot. The first bit should return the error to the user and the second should do whatever with it lol.

<?php
// Start a session
session_start();

// Correct details to login
$usernameCorrect = "admin";
$passwordCorrect = "admin123";

// Check on submission
if(isset($_POST['submit'])) {
    // Make it simpler on us for later use
   // It'd be smart to clean the input, but since I don't know
   // if you're using MySQL or PDO, or MySQLi I'll let you do that
   $usernameInput = $_POST['username'];
   $passwordInput = $_POST['password'];
   
   // Check if matches what we want
   if($usernameInput != $usernameCorrect || $passwordInput != $passwordCorrect) {
      // It does not match
   } else {
      // It does match
   }
}
?>
<form method="post">
    <input name="username" type="text" placeholder="Username..">
   <input name="password" type="text" placeholder="Password..">
   <input name="submit" type="button" value="Submit">
</form>
#9. Posted:
Status: Offline
Joined: Jan 25, 20161 Year Member
Posts: 108
Reputation Power: 11
Forgot to post this but i found a way around it, thanks for the help tho guys!
Users browsing this topic: None
Jump to:


RECENT POSTS

HOT TOPICS