Solved

Log in and change password behavior

Posted on 2016-08-30
5
32 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 52

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 108

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 52

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

912 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now