Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login Password Security 1

Status
Not open for further replies.

jasonkeller

Programmer
May 23, 2001
16
US
I have created an user administration in coldfusion and access and I was curious to whether there is a way to secure a password so that the password given to the user can only be used by that user from a certain computer. That way that user cannot give it out to another person to view with out permission. Like our competitors.
 
There are some semi-secure methods.

Such as dropping a cookie on the computer when they sign-up that must be present when logging in. Which wont work of cookies are turned off or if the same person tries to log in from there laptop. You can check the IP address of the user (but it will change if they are on a dial-up and disconnect).

I can't think of any other ways right now... Anybody else?

Hope it helps.


 
The cookie method is probably the best method and what I would use. If you really wanted to ensure it would work without cookies though, you could password protect each session and require the visitor to receive a new password via e-mail for each new session. This is more of a nuisance but will make it harder to share passwords. The original user would have to send the cfid, cftoken, & new password (if they even knew how) to the competitor within the session timeout for them to be able to get in. Just a matter of whether nuisance factor is worth the assurance that it will work without cookies.

GJ

 

I would set a cookie (with <CFCOOKIE... ) with the value of the ID that corresponds with the UserName and Password.

Then when you verify the UserName and Password Login also check to make sure there is a Cookie with the value of the ID.

You would write your Cookie like this:
<CFCOOKIE name=&quot;VerifyLogin&quot; value=&quot;#ID#&quot;>

When you insert the UserName and Password into the database there are a few ways that you can get the ID. What I usually do when it is login info is check to be sure the UserName and Password are not allready in the database then simply query for them after inserting them.

Then when you verify login add

<CFIF Cookie.VerifyLogin eq #ID#>

If you have trouble with any part of it let us know.


 
I am not sure how to incorperate the verifylogin into what I have. I am new at the coldfusion thing. Anyways Below is my login page. When the user submits is login and password, it then is posted to display.cfm where I have used
<CFINCLUDE TEMPLATE=&quot;smileauthenticateusers.cfm&quot;>
for security of the display.cfm.


<FORM ACTION=&quot;display.cfm&quot; METHOD=POST>

Username:<INPUT TYPE=&quot;text&quot; NAME=&quot;UserName&quot;
<CFIF #ParameterExists(Cookie.Username)# IS &quot;Yes&quot;>VALUE=&quot;<CFOUTPUT>#Cookie.Username#</CFOUTPUT>&quot;</CFIF>>

Password:</B><INPUT TYPE=&quot;password&quot; NAME=&quot;Password&quot;
<CFIF #ParameterExists(Cookie.Password)# IS &quot;Yes&quot; >VALUE=&quot;<CFOUTPUT>#Cookie.Password#</CFOUTPUT>&quot;</CFIF>>



<INPUT TYPE=&quot;submit&quot; VALUE=&quot; Login Now &quot; >&nbsp;
<INPUT TYPE=&quot;reset&quot; VALUE=&quot; Restart &quot; >

</form>
 
Hi again JasonKeller,

It would probably work something like this:

<CFIF #ParameterExists(Cookie.VerifyLogin)# is &quot;Yes&quot;>
<CFQUERY name=&quot;GetUser&quot; datasource=&quot;#DSN#&quot;>
Select *
From EmployeeTable
Where EmployeeID = #Cookie.VerifyLogin#
</CFQUERY>
</CFIF>
<FORM ACTION=&quot;display.cfm&quot; METHOD=POST>

Username:<INPUT TYPE=&quot;text&quot; NAME=&quot;UserName&quot;
<CFIF #ParameterExists(GetUser.Username)# IS &quot;Yes&quot;>VALUE=&quot;<CFOUTPUT>#GetUser.Username#</CFOUTPUT>&quot;</CFIF>>

Password:</B><INPUT TYPE=&quot;password&quot; NAME=&quot;Password&quot;
<CFIF #ParameterExists(GetUser.Password)# IS &quot;Yes&quot; >VALUE=&quot;<CFOUTPUT>#GetUser.Password#</CFOUTPUT>&quot;</CFIF>>



<INPUT TYPE=&quot;submit&quot; VALUE=&quot; Login Now &quot; >
<INPUT TYPE=&quot;reset&quot; VALUE=&quot; Restart &quot; >

</form>

Remember the point is to have something in the cookie that they cannot easily tell is there username and password. That is why you drop the ID from the Database instead of the username and password itself. This then, looks for the ID in the Cookie, if it is there then it searches the Database for the Username and Password that go along with it.

In order to get that ID into the cookie you would do something like this: When they first sign-up they fill out a form that they choose a username and a password and fill in whatever other info you need then they submit that. When they submit it you check to be sure that there is not allready that combination of username and password in the Database and if there isn't then you insert it into the Database. Immediately after that Query the Database like this:

<CFQUERY name=&quot;getID&quot; datasource=&quot;#DSN#&quot;>
Select *
From EmployeeTable
Where Username= #Form.Username#
AND Password = #Form.Password#
</CFQUERY>

<CFCOOKIE name=&quot;VerifyLogin&quot; value=&quot;#GetID.EmployeeID#&quot;>

That should do it. If you can't tell where that code goes then post you page for inserting new people into the database and I'll see if I can figure it out.

Hope it helps.
 

So the following information - - - goes on my insert page?

CFQUERY name=&quot;getID&quot; datasource=&quot;#DSN#&quot;>
Select *
From EmployeeTable
Where Username= #Form.Username#
AND Password = #Form.Password#
</CFQUERY>

<CFCOOKIE name=&quot;VerifyLogin&quot; value=&quot;#GetID.EmployeeID#&quot;>

After the Admin enters the info, this is my insert page.
I have tried it (I Think i did it right), but I am getting a duplicate index, or primary key duplicate error. Do I need to set up an new record for a different id indexed with no duplicates?


<CFINSERT Datasource=&quot;smile&quot; Tablename=&quot;admin&quot; FormFields=&quot;name,email,username,password&quot;>
<HTML>
<HEAD>
<TITLE>Adding New User . . . Please Wait</TITLE>
<meta http-equiv=&quot;refresh&quot; content=&quot;1;url=useradmin.cfm&quot;>
</HEAD>

<BODY>
<CENTER><FONT COLOR=black FACE=&quot;Arial&quot; size=4><b>Adding New User . . . Please Wait</b></FONT></CENTER>

</BODY>
</HTML>

 
I'm not positive but I think you might be doing this in the wrong order.

try it like this. This is your insert page:

Code:
<CFINSERT Datasource=&quot;smile&quot; Tablename=&quot;admin&quot; FormFields=&quot;name,email,username,password&quot;>
<CFQUERY name=&quot;getID&quot; datasource=&quot;#DSN#&quot;>
  Select *
  From admin
  Where username= #Form.Username# 
  AND password = #Form.Password#
</CFQUERY>

<CFCOOKIE name=&quot;VerifyLogin&quot; value=&quot;#GetID.ID#&quot;>

<HTML>
<HEAD>
    <TITLE>Adding New User . . . Please Wait</TITLE>
<meta http-equiv=&quot;refresh&quot; content=&quot;1;url=useradmin.cfm&quot;>
</HEAD>

<BODY>
<CENTER><FONT COLOR=black FACE=&quot;Arial&quot; size=4><b>Adding New User . . . Please Wait</b></FONT></CENTER>

</BODY>
</HTML>


I tried to adjust this for your table names and your field names. I'm not positive what your primary key field is named but whatever it is named make sure that is what you put in the red part.

<CFCOOKIE name=&quot;VerifyLogin&quot; value=&quot;#GetID.ID#&quot;>

Otherwise, if that doesn't help, the error sounds like you are trying to do an insert with a primary key field filled in. if one of these fields &quot;name,email,username,password&quot; is the primary key that wont work. You will need to add another field. Most people call it ID or User_ID or something like that. Make sure it is the primary key and that it is set to AutoNumber. Then when you insert just ignore it. Don't put it in the Formfields part. The database will take care of it.

If it still isn't working E-mail me both pages (or post them if you want) and I'll see what I can do.
 
By #DSN# do you mean my &quot;smile&quot; datasource or is that a reserved tag or something
<CFQUERY name=&quot;getID&quot; datasource=&quot;#DSN#&quot;>
 
I believe I have it setup right. Here is the error I am getting. My primary key is persons_id and it is set up as an auto number.
------------------------------------------------------------
ODBC Error Code = 23000 (Integrity constraint violation)
[Microsoft][ODBC Microsoft Access Driver] The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

The error occurred while processing an element with a general identifier of (CFINSERT), occupying document position (1:1) to (1:89).
------------------------------------------------------------
User Login form:
----------------
<CFIF #ParameterExists(Cookie.VerifyLogin)# is &quot;Yes&quot;>
<CFQUERY name=&quot;GetUser&quot; datasource=&quot;smile&quot;>
Select *
From Admin
Where persons_id = #Cookie.VerifyLogin#
</CFQUERY>
</CFIF>
<HTML>
<HEAD>
<TITLE>MJ Grant Company</TITLE>

</HEAD>
<BODY leftMargin=0 topMargin=0 MARGINHEIGHT=&quot;0&quot; MARGINWIDTH=&quot;0&quot; BGCOLOR=#93989B VLINK=BLACK ALINK=BLACK LINK=BLACK>
<TABLE CELLPADDING=&quot;0&quot; CELLSPACING=&quot;0&quot; BORDER=&quot;0&quot; Align=center>
<TR>
<TD ALIGN=CENTER><BR>
<FONT SIZE=2 COLOR=black FACE=&quot;Arial&quot;><FONT SIZE=4 COLOR=Black FACE=&quot;Arial&quot;><B><IMG SRC=&quot;../images/smileheader.jpg&quot; WIDTH=333 HEIGHT=77><BR></B>
<CENTER><FONT SIZE=2 COLOR=white FACE=&quot;Arial&quot;>For a secure account number,<BR>please contact us at: <BR><B>(480) 736-8646 #205 or <A HREF=&quot;mailto:gstousland@mjgrant.com?subject=Requesting Secure Account&quot;>email us.</A></B></FONT></FONT></CENTER><br><BR>
<FONT SIZE=2 COLOR=black FACE=&quot;Arial&quot;>If you already have secure account,<br>Please enter your<B> Username</B> and <B>Password</B>:</FONT><BR><BR></TD>
</TR>
</TABLE>
<TABLE BORDER=0 align=center>
<TR>
<TD ALIGN=CENTER>
<FORM ACTION=&quot;display.cfm&quot; METHOD=POST>
<FONT FACE=&quot;Arial&quot; SIZE=2 color=black><B>Username:</B></FONT>&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE=&quot;text&quot; NAME=&quot;UserName&quot;
<CFIF #ParameterExists(GetUser.UserName)# IS &quot;Yes&quot;>VALUE=&quot;<CFOUTPUT>#GetUser.UserName#</CFOUTPUT>&quot;</CFIF>> </TD>
</TR>
<TR>
<TD ALIGN=CENTER><FONT FACE=&quot;Arial&quot; SIZE=2 color=black><B>Password:</B></FONT>&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE=&quot;password&quot; NAME=&quot;Password&quot;
<CFIF #ParameterExists(GetUser.Password)# IS &quot;Yes&quot; >VALUE=&quot;<CFOUTPUT>#GetUser.Password#</CFOUTPUT>&quot;</CFIF>>



</TD>
</TR>
</TABLE>
<TABLE BORDER=0 ALIGN=CENTER>
<TR>
<TD ALIGN=CENTER><BR>&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE=&quot;submit&quot; VALUE=&quot; Login Now &quot; style=&quot;background-color:#93989B; color:#000000; alpha(opacity=90)&quot;>&nbsp;<INPUT TYPE=&quot;reset&quot; VALUE=&quot; Restart &quot; style=&quot;background-color:#93989B; color:#000000; alpha(opacity=90)&quot;></TD>
</TR>
</TABLE>
</form>


</BODY>
</HTML>
------------------------------------------------------------
Admin Form to add new user:
---------------------------
<HTML>
<HEAD>
<TITLE>Smile.MJGrant.com Add New User Account</TITLE>

</HEAD>
<BODY leftMargin=0 topMargin=0 MARGINHEIGHT=&quot;0&quot; MARGINWIDTH=&quot;0&quot; VLINK=Red ALINK=Red LINK=Red><BR>
<CENTER><FONT SIZE=4 FACE=&quot;Arial&quot;><B>Smile.MJGrant.com Add New User Account</B><BR></CENTER>
<CENTER><FONT SIZE=3 COLOR=Black FACE=&quot;Arial&quot;><A HREF=&quot;smile.cfm&quot;>Back To Admin Page</A>&nbsp;&nbsp;
<A HREF=&quot;smilelogin.cfm&quot;>Logout</A></FONT></CENTER><BR>
<FORM METHOD=POST ACTION=&quot;processuser.cfm&quot;><BR>
<TABLE BORDER=0 align=center>
<TR>
<TD><FONT FACE=&quot;Arial&quot; COLOR=&quot;black&quot; size=2>Users Name:</FONT></TD>
<TD><INPUT TYPE=text NAME=&quot;name&quot; SIZE=25 MAXLENGTH=45></TD>
</TR>
<TR>
<TD><FONT FACE=&quot;Arial&quot; COLOR=black size=2>Email Address:</FONT></TD>
<TD><INPUT TYPE=text NAME=&quot;email&quot; SIZE=45 MAXLENGTH=45></TD>
</TR>
<tr><td><p>&nbsp;</p></td></tr>
<TR>
<TD><FONT FACE=&quot;Arial&quot; COLOR=&quot;black&quot; size=2>Users Login:</FONT></TD>
<TD><INPUT TYPE=text NAME=&quot;username&quot; SIZE=25 MAXLENGTH=25></TD>
</TR>
<TR>
<TD><FONT FACE=&quot;Arial&quot; COLOR=&quot;black&quot; size=2>Users Password:</FONT></TD>
<TD><INPUT TYPE=text NAME=&quot;password&quot; SIZE=25 MAXLENGTH=25></TD>
</TR>
<TR>
<TD></TD>
<TD><INPUT NAME=&quot;Submit&quot; type=&quot;submit&quot; VALUE=&quot;Add New User&quot; ALIGN=top><INPUT NAME=&quot;reset&quot; type=&quot;reset&quot; value=&quot;Reset&quot; ALIGN=absbottom></TD>
</TR>
</TABLE><BR>
<CENTER>


</CENTER>
</FORM>
</BODY>
</HTML>
------------------------------------------------------------
Processing Page/Insert Page:
----------------------------
<CFINSERT Datasource=&quot;smile&quot; Tablename=&quot;admin&quot; FormFields=&quot;name,email,username,password&quot;>
<CFQUERY name=&quot;getID&quot; datasource=&quot;smile&quot;>
Select *
From admin
Where UserName= #Form.UserName#
AND Password = #Form.Password#
</CFQUERY>

<CFCOOKIE name=&quot;VerifyLogin&quot; value=&quot;#GetID.persons_id#&quot;>
<HTML>
<HEAD>
<TITLE>Adding New User . . . Please Wait</TITLE>
<meta http-equiv=&quot;refresh&quot; content=&quot;1;url=useradmin.cfm&quot;>
</HEAD>

<BODY>
<CENTER><FONT COLOR=black FACE=&quot;Arial&quot; size=4><b>Adding New User . . . Please Wait</b></FONT></CENTER>

</BODY>
</HTML>

I really appreciate this help!


 
Well isn't that just a kick in the pants.
Sorry it took so long to get back, I was out of town.

That Insert code looks OK. I am assuming that the problem you're having is when you try to register a user from the admin page, it calls the Insert page and throws that error. I would check to see if any of your other fields are set to not allow duplicates, or if you have relationships set that aren't working out. More likely you have another field set to not allow duplicates. make sure that the only field that cannot allow duplicates is the primary key.

Starting to sound like a database problem. We'll get it though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top