Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Building A Login System

Asked Modified Viewed 785 times
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
asked
Senior Member

Can someone please tell me why this doesn't seem to work right? I can't get my scripts to honor SESSION variables. I'm running 9.03.110 and my scripts are running Bootstrap 4.

This is from my login script.
   $username = stripinput($_POST['username']);
   $pass = stripinput($_POST['password']);
$result = dbquery("SELECT * FROM ".DB_MY_TABLE." WHERE active='1' AND username='$username'");
   while($data = dbarray($result)) {
      $username = $data['username'];
      $_SESSION['user'] = $username;
      $password = $data['password'];
      if(password_verify($pass, $password)) {
         $_SESSION['valid'] === true;
         }
      }
   }
   redirect(BASEDIR."my_dir/my_file.php");
}

And this is from my register script.
if(isset($_POST['username']) && !empty($_POST['email']) && !empty($_POST['password'])) {
   $username = stripinput($_POST['username']);
   $email = stripinput($_POST['email']);
   $password = stripinput($_POST['password']);
      $hash = password_hash($password, PASSWORD_DEFAULT);
   $reg_time = date("Y-m-d");
   $active = 1;
$result = dbquery("INSERT INTO ".DB_MY_TABLE." (acct_id, username, email, password, reg_time, active) VALUES ('', '$username', '$email', '$hash', '$reg_time', '$active')");
   $_SESSION['valid'] === false;
   }
   redirect(BASEDIR."my_dir/login.php");
}
Edited by Grimloch on 16-03-2021 20:33,
0 replies

4 posts

D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

Two things I See:

1 - In the register script you are inserting the acct_id field, which I believe is Autoincrement? Don do this.
2 - Not use stripinputs for password, unless you are using Welcome01 as password. I can tell you having problems with complex passwords i.c. stripinput.
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

Thanks for your input douwe.
#1 it's OK to use the increment field as long as you show a null for the it's value but I can change that. But the register script works fine, the user info is inserted in the table that's not my problem.
#2 you're right using stripinput is not a good idea; easily changeable.

What I am trying to find out is if I'm doing the session variables correctly because it doesn't work right. If I stop a script mid-point with a print session and then exit, it shows nothing for the session variables.
0 replies
D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

And of course you called a session_start() before?
1 reply
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

Of course! Every script/page that uses a session variable.
0 replies

Labels

Statistics

  • Views 0 views
  • Posts 4 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

G
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
D
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet