Solved

Log in and change password behavior

Posted on 2016-08-30
5
37 Views
Last Modified: 2016-08-30
Dear experts,
I use below article for my php login-log out
Thanks to Ray Pasuer

What I want to do is, if my user login for the first time I'd like to my user to change his password.

What do you suggest i should do?

I think i should create another coloumn on my users table to insert another value like IP address then check if the ip address has a data? If not, after a successful log in, i can redirect the page; or for better i can create another table to store log in data and check the users log in if it's first time or not...

What do you suggest I should do?

https://www.experts-exchange.com/articles/2391/PHP-Client-Registration-Login-Logout-and-Easy-Access-Control.html
0
Comment
Question by:Braveheartli
  • 2
  • 2
5 Comments
 
LVL 54

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 total points
ID: 41775914
You can add a field that stores anything in it and check that for a status. The best solution is to pick a field that will be useful in the future - for instance - last login. This only gets set once a user has changed their password - after that it is updated every time they login. That way the field is not dead weight on your table.

If you are going to maintain an audit trail in a separate log database - that can also be used but then you have to query two tables to check status - whereas with the last-login suggestion you can do it in one.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 41776076
If you're using the design in the article, the user will register before using the site.  During the registration, the user must provide and verify his password.  To my mind, it does not make much sense to ask the user to choose and verify a password, then immediately ask the user to change the password.  So I would not recommend that.

If you're looking for a design that indicates whether a user has visited a site, this article shows the register-and-confirm design.  It's pretty simple - we just set an INT column value to indicate whether an action has been taken.  The same could be done for a password change.

If you're looking for a little more sophisticated view of a user's visits, you might change the INT into a TIMESTAMP column.  Then MySQL will update the TIMESTAMP any time an element of data in the corresponding row gets changed.  This will give you an easy way to know the last time the password was changed, because a password update will change the user's row in the table, and the TIMESTAMP column will get updated.  You can do more with this design by incorporating the TIMESTAMP column into the WHERE clause of your queries.  For example, you can write a query to find all of the users who have not changed their passwords in the last month.  Or you can write a query to see which users have changed their passwords most recently, etc.  More details here:
https://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html
0
 
LVL 54

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 total points
ID: 41776118
if you're looking for a little more sophisticated view of a user's visits, you might change the INT into a TIMESTAMP column.  Then MySQL will update the TIMESTAMP any time an element of data in the corresponding row gets changed.

... if you set the field to CURRENT_TIMESTAMP on update

From http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
Default the field to CURRENT_TIMESTAMP and set to CURRENT_TIMESTAMP on update
CREATE TABLE t1 (
  ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

Open in new window

0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 41776131
Yeah, that's why I posted the link.
 
Here's 5.5:
With neither DEFAULT CURRENT_TIMESTAMP nor ON UPDATE CURRENT_TIMESTAMP, it is the same as specifying both DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP.
And here's 5.7, same functionality, but better explanation:
TIMESTAMP and DATETIME columns have no automatic properties unless they are specified explicitly, with this exception: By default, the first TIMESTAMP column has both DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP if neither is specified explicitly.

You've got to wonder what the authors were thinking when they designed a system where both the presence and absence of a control setting meant the same thing!

Man pages changed some between 5.5 or 5.7, but as a practical matter there is not much difference in functionality there.  I've never seen a table with more than one TIMESTAMP column, but I guess there is always some way to make things "interesting!"
1
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 41776231
Thank you
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question