You are viewing our Forum Archives. To view or take place in current topics click here.
Anyone here decent at PHP?
Posted:

Anyone here decent at PHP?Posted:

iGouldz
  • Challenger
Status: Offline
Joined: Jan 25, 20168Year Member
Posts: 119
Reputation Power: 12
Status: Offline
Joined: Jan 25, 20168Year Member
Posts: 119
Reputation Power: 12
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
  • TTG Addict
Status: Offline
Joined: Oct 09, 201013Year Member
Posts: 2,358
Reputation Power: 106
Status: Offline
Joined: Oct 09, 201013Year Member
Posts: 2,358
Reputation Power: 106
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:
iGouldz
  • Challenger
Status: Offline
Joined: Jan 25, 20168Year Member
Posts: 119
Reputation Power: 12
Status: Offline
Joined: Jan 25, 20168Year Member
Posts: 119
Reputation Power: 12
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
  • Resident Elite
Status: Offline
Joined: May 16, 20176Year Member
Posts: 232
Reputation Power: 72
Status: Offline
Joined: May 16, 20176Year Member
Posts: 232
Reputation Power: 72
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
  • Resident Elite
Status: Offline
Joined: May 16, 20176Year Member
Posts: 232
Reputation Power: 72
Status: Offline
Joined: May 16, 20176Year Member
Posts: 232
Reputation Power: 72
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
  • Winter 2017
Status: Offline
Joined: Dec 30, 201211Year Member
Posts: 3,778
Reputation Power: 3016
Status: Offline
Joined: Dec 30, 201211Year Member
Posts: 3,778
Reputation Power: 3016
Are you talking about PHPMyAdmin?
[ Register or Signin to view external links. ]

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
  • PC Master Race
Status: Offline
Joined: Aug 19, 201013Year Member
Posts: 5,238
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201013Year Member
Posts: 5,238
Reputation Power: 532
Ryzen wrote 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!


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
  • Resident Elite
Status: Offline
Joined: May 16, 20176Year Member
Posts: 232
Reputation Power: 72
Status: Offline
Joined: May 16, 20176Year Member
Posts: 232
Reputation Power: 72
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:
iGouldz
  • Challenger
Status: Offline
Joined: Jan 25, 20168Year Member
Posts: 119
Reputation Power: 12
Status: Offline
Joined: Jan 25, 20168Year Member
Posts: 119
Reputation Power: 12
Forgot to post this but i found a way around it, thanks for the help tho guys!
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.