Solved

Log in and change password behavior

Posted on 2016-08-30
5
25 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 51

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 51

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

13 Experts available now in Live!

Get 1:1 Help Now