?
Solved

how to have password fill in automatically on login page

Posted on 2005-04-04
20
Medium Priority
?
962 Views
Last Modified: 2010-04-06
Hi,

I am creating a login page for an app (written in php but I don't think that matters in this case). How do I make it so that once they've logged in one time, the next time the fill in their login name, the password is already filled in. Do I need to set a cookie?

Thanks.
0
Comment
Question by:alpineer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
  • +4
20 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 13698490
Well normally this is an operating system setting, you know when it pops up and asks if you would like to save the username and password.

But if you want to set up a cookie you could use this to not only save their password but actually eliminate the login process.  Have the login page scan for a cookie, if one is found, read the content, query thi against the database and log them in, check www.w3schools.com/asp/

and check the cookies section for more info
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 13698792
apresto is correct; you can eliminate the login process entirely by saving a cookie after a successful login attempt.  By using php (or whatever) to fill in the password field means displaying the password in the source code, which is a massive security risk, as anyone sharing the machine could view this.
0
 

Author Comment

by:alpineer
ID: 13698998
I can't login them in automatically. Even though they will only be using this from their office, they change computers often (ie move from desk to desk) so the same person isn't always at the same computer.

I just wanted it to fill in the password edit box automatically when they fill in the username edit box. Basically so I can convince them to have more secure passwords. They won't be easy to remember so I want the field to be filled out automatically, if possible.

I am using IE 6 and it doesn't ask me if I want to save the password. It is defined as a password input field. The username is remembered. I just tried on another computer that I've never used to login and it didn't ask me either (again IE 6).

Any ideas? Could it be because I have other fields on the form than just username and password?

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:Saber37886661
ID: 13703749
What is your server OS?
We used to do something simular with a Novell script which would grab thier Novell username and compare it to the 1 in the SQL database for the intranet site, which would then ship the intranets username and password back tho the user using ASP, and then javascript to automatically go to the next url. eg http://blah.com?uname=<%username%>&pass=<%pass%>

doing it this way gets around the office chair swapping bit....but u then have to enforce passwords more vigorously
0
 

Author Comment

by:alpineer
ID: 13704591
Server is unix. App is php. But I think I need something client side, like a cookie.
0
 

Author Comment

by:alpineer
ID: 13704596
So if I do save their login info in a cookie, how do I then use that info to fill in the password field when they type the username. Sounds like I need to javascript to do this.
0
 
LVL 3

Expert Comment

by:Saber37886661
ID: 13704857
check out this page, kinda easy explanation with the depth u need.
http://tech.irt.org/articles/js025/index.htm
0
 
LVL 5

Expert Comment

by:jericotolentino
ID: 13714349
>> I just wanted it to fill in the password edit box automatically when they fill in the username edit box. Basically so I can convince them to have more secure passwords. They won't be easy to remember so I want the field to be filled out automatically, if possible.

All right, good point. You can also use $_SESSION if you're going with PHP.

Just do something like this on your login verification script...

session_start();
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];

Then on the page where the user edits the password, just place these lines.

session_start();
if((!$_SESSION['username']) || (!$_SESSION['password'])) {
header("location: login.php");
exit;
}

;-)
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 13745993
You can use "Remember Me" feature so that the username/password is stored in the client computer as cookie and next time they don't need to enter their login info again. Here's a how-to-do description: http:Q_21086125.html

>> I just wanted it to fill in the password edit box automatically when they fill in the username edit box. Basically so I can convince them to have more secure passwords. They won't be easy to remember so I want the field to be filled out automatically, if possible

If you consider having more secured password, storing the info in cookie is NOT a good idea too!

Have a seperate DB table that stores the login information (user name or userid) with the time of expiry and a unique random string. Store the unique random string in the DB as well as in the cookie, so the original login information is not revealed to the public!
0
 

Author Comment

by:alpineer
ID: 13746597
For some reason, I just can't seem to get through on this one. I do not want to log the user in automatically, as in the remember me example. I do not want the user to go to the home page of the app and automatically be logged in as joeuser. I can't have this because in the office, several people share the same computer. So it might be maryuser sitting at the keyboard instead of joeuser.

What I was hoping to do would be that when joeuser types in his usernameand hits the tab key, his password would already be in the password edit box. (this, of course, only after he has logged in at least one before). I want the user to type in their username but not have to type in their password.

It happend right here on EE. I just logged out (I was automatically logged in). I went to the home page, typed in my username and the first time I had to type in my password. I logged out again. Went to the home page. Typed in my username, hit the tab key and voilà, there was my password already typed for me. So it is happening client side as soon as the username edit box loses focus.

This is what I wanted to do. I hope it is clearer now. I've upped the points.
0
 
LVL 25

Accepted Solution

by:
Rouchie earned 1000 total points
ID: 13750837
This is browser functionality and not server/client-side code.  Most browsers now will remember all usernames and/or passwords and enter them automatically.  If numerous passwords are stored for one username box, you may even see a list of these user names when you come to edit the text in that box.

Therefore you need to make sure the browser will remember these details.  In most office environments this is disabled for security reasons, so you might need to enable them again.

 In IE,  goto Tools > Internet Options > Content > AutoComplete > Enable Usernames and Passwords on forms
 In Mozilla, goto Tools > Options > Privacy > Saved Passwords > Enable Remember Passwords

If you do not want to use built-in browser functionality, you'll have a tricky job of outputting all passwords into the HTML code then using javascript to fill-in the password field based on the user name.  This would be quite awkward but I'm sure there's plenty of users on EE who could do this for you.  The result may not work across all browsers as intended though because the browser-functionality detailed above would interfere with your javascript.
0
 

Author Comment

by:alpineer
ID: 13750942
Thanks, Rouchie. Your response makes perfect sense. And I definitely want to use built-in browser functionality. It just doesn't work for some reason!

I have IE 6 on Win XP. The browser never asked me to save the password, as happens with other sites.

I checked my browser settings and all autocomplete checkboxes were checked. Even prompt me to save...

And in the username edit box, all previous usernames have been saved. When I type in the first letter, I get the dropdown with the list. If I choose one of them, I should get the related password, but I don't.

Here is my form:

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="600" border="0" align="center" cellpadding="4" cellspacing="0">
      <tr>
        <td colspan="2" align="right" class="mandatory">required fields</td>
        </tr>
      <tr>
        <td align="right" class="mandatory">User name:</td>
        <td><input name="username" type="text" id="username" size="16" maxlength="16"></td>
        </tr>
      <tr>
        <td align="right" class="mandatory">Password:</td>
        <td><input name="password" type="password" id="password" size="16" maxlength="16"></td>
      </tr>
      <tr>
        <td align="right" class="mandatory">Op sig:</td>
        <td><input name="initials" type="text" id="initials" size="4" maxlength="2"></td>
      </tr>
      <tr>
        <td align="center">&nbsp;</td>
        <td><input name="maint" type="checkbox" id="maint" value="1">Do maintenance? </td>
        </tr>
      <tr>
        <td align="center">&nbsp;</td>
        <td><input type="submit" name="Submit" value="Login" onClick="return(checkForm());"></td>
        </tr>
    </table>
      </form>


Any idea why this wouldn't work with autocomplete? As I said, it does store the username field, just not the password. And this does work for me on the login page for EE. I also tried on another computer I have here. IE 6 on Win2k. It doesn't work there either.

0
 
LVL 25

Expert Comment

by:Rouchie
ID: 13750961
I've had a similar problem.  Open the browser on a blank page, then go into the AutoComplete box and uncheck all the 4 options, then press *both* CLEAR buttons to wipe all usernames and passwords.  Press OK and close the browser completely.

Open a fresh browser window and go back into AutoComplete again.  Now re-check all the boxes so they are enabled, press OK and close the browser.

Now when the browser is opened (again!) and the page with the username/password fields is used, it should once again start asking you to save the information you enter once you try to login.

Note that if at any one time you check the box saying "Do not prompt to remember passwords..." it will mess up the above settings and probably not prompt again despite being re-enabled!  Then you'll have to repeat the above all over again!

Not sure why this happens but that's the way I managed to fix it for me...!
0
 

Author Comment

by:alpineer
ID: 13751194
I tried your suggestion. Actually, even before I read it I decided to try to clear all passwords. But the browser hangs. I read somewhere that I should have tried clearing all form data before passwords. Then I read elsewhere to delete the SPW key on the Intelliforms entry in the registry to resolve the browser hanging problem. Did that to but it still hangs whether I click clear form data or passwords. And it doesn't seem to be deleting anything. I still have all my usernames in the edit box.

Anyway, I went through your routine, except for clearing the data and it made no difference.

Any other ideas?
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 13752849
If the browser hangs then sadly this seems like a browser issue and not a code-related issue - sorry!  

It should only take a couple of seconds to clear the user and password data (unless you have hundreds of people sharing machines).  Nothing should hang and the data should definitely be deleted.

I think the problem therefore may be out of scope for this question area...
The only other thing I would suggest is making sure you are logged in as the administrator account before clearing the data.

If you don't have the time to reinstall browser / service packs etc then you could always download an alternative browser such as firefox for example - just for testing purposes for this problem...???
0
 
LVL 27

Assisted Solution

by:Asta Cu
Asta Cu earned 1000 total points
ID: 13752881
Have you again cleared the cache (IE temp files including offline content and history files); cleared any related cookies to recreate and unchecked all autocomplete items, closed IE and tried again to recheck the autocomplete items you want?  Any changes made to IE need to have IE closed/reopened to ensure changes are made...  Multiple users involved?

This from IE Help...
To delete Autocomplete entries from the Address bar list

The AutoComplete feature saves previous entries you've made for Web addresses, forms, and passwords. To delete entries from the Address bar, you must clear your History folder. You cannot clear individual entries from the list of saved entries.

On the Tools menu in Internet Explorer, click Internet Options.
Click the General tab.
Under History, click Clear History.
 Notes

When typing information in Web forms, and typing passwords, you can remove an item from the list of suggestions by clicking the item and then pressing the DELETE key.
For Help on an item, click  at the top of the dialog box, and then click the item.
0
 
LVL 27

Expert Comment

by:Asta Cu
ID: 13752893
0
 

Author Comment

by:alpineer
ID: 13753410
You guys will never believe this. I kept asking myself, without any special code on the page, how does the browser know to pair up the username/password fields. They don't have to be named in any special way. In fact, I asked above if the fact that I have some extra fields on the form makes any difference. AND IT DOES!

I have a username, a password (of type password), another edit box and a check box. I took off the extra edit box and all works like a charm. I guess for this to work you can only have one input of type text and another of type password. Any other edit boxes throws things off. Checkboxes don't seem to cause any problems. In fact, there is often a remember me checkbox on login forms.

I tried this on the computer that hangs and on another. Both work fine. I put the extra edit box back and it stopped working.  

Thanks to all who contributed. Even though I finally figured this out myself, I will divvy up the points to those of you who put me on the path to the solution.

0
 
LVL 25

Expert Comment

by:Rouchie
ID: 13754714
No probs alpineer, glad you got it sorted...!  :-)
0
 
LVL 27

Expert Comment

by:Asta Cu
ID: 13758044
Yay!  Good news, thank you.  ":0)  This can also help others now that it's moved to our PAQ.
Best wishes to you,
":0) Asta
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

770 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