Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Other Languages

Post new topic   Reply to topic
How do I use these snippets with this login script?
View previous topic :: View next topic  
Author Message
ammo325
Newbie


Joined: 10 Feb 2004
Posts: 5

PostPosted: Feb 10th, 2004 11:07 AM    Post subject: How do I use these snippets with this login script? Reply with quote

I have one login script and two snippets. One snippet is for making passwords that are strong, the other snippet is to check passwords entered ensuring they are strong. How do I use one of the password snippets with the Login script?

Here are the scripts:
LOGIN SCRIPT -

The login script I have is VB and I cannot figure out where to insert these codes.

Here is my script:

Code:
<%
Option Explicit
Dim strError, strSQL, objRS
'see if the form has been submitted
If Request.Form("action")="login" Then
'the form has been submitted

'// validate the form

'check if a username has been entered
If Request.Form("username") = "" Then _
strError = strError & "- Please enter a username
" & vbNewLine

'check if a password has been entered
If Request.Form("password") = "" Then _
strError = strError & "- Please enter a password
" & vbNewLine

'// check if an error has occured
If strError = "" Then
'continue
'include database connection code
%>
<!--#include file="inc-dbconnection.asp"-->
<%

'// create the SQL
strSQL = "SELECT id,password FROM members WHERE username='" & _
fixQuotes(Request.Form("username")) & "'"

'// run the SQL
Set objRS = oConn.Execute (strSQL)
'// see if there are any records returned
If objRS.EOF Then
'no username found
strError = "- Invalid username or password
" & vbNewLine
Else
'check password
If objRS("password")=Request.Form("password") Then
'username/password valid
'save session data
Session("loggedin") = True
Session("userid") = objRS("id")
'redirect to members area
Response.Redirect ("default.asp")
Response.End
Else
'invalid password
strError = "- Invalid username or password
" & vbNewLine
End If
End If

End If
If strError <> "" Then
'output the error message
'add extra HTML...
strError = "<p><font color=""#FF0000"">The following errors occured:" & _
"</font>
" & vbNewLine & strError
End If
'display message in URL.. (ie thank you for registering)
If Request.QueryString("msg") <> "" And strError = "" Then
strError = "<p>" & Request.QueryString("msg") & "</p>"
End If
End If

Function fixQuotes(strData)
fixQuotes = Replace(strData,"'","''")
End Function're-set session data (ie log out)Session("loggedin")=""
Session("userid")=""
%>
<html>
<head>
<title>Members Area Login</title>
</head>
<body>
<h1>Members Area Login</h1>
<p>Please enter your username and password to access the Members Area.</p>
<%=strError%>
<form action="login.asp" method="POST">
<input type="hidden" name="action" value="login">
<table border="0">
<tr>
<td><b>Username</b></td>
<td><input type="text" maxlength=20 name="username"
value="<%=Server.HTMLEncode(Request.Form("username"))%>"></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input type="password" maxlength=20 name="password"
value="<%=Server.HTMLEncode(Request.Form("password"))%>"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>

MAKE PASSWORD SNIPPET -
This snippet makes strong passwords when the user registers:


<%
Private Function MkPassword(byVal length)
Const specchars = "@#$?_-\/*&"
Const alphabetnumbers = _
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Dim max, loc, i, a, tmp
Dim wordarray()
If IsNumeric( length ) Then
max = 62 : loc = alphabetnumbers
Else
MkPassword = Null
Exit Function
End If
tmp = ""
For i = 1 to CInt( length - 1 )
Randomize
a = CInt( Rnd * Max ) + 1
Randomize
a = CInt( Rnd * a ) + 1
if a > Max or a < 1 then a = 3
tmp = tmp & Mid( loc, a, 1 )
Next
tmp = StrReverse( tmp )
Randomize
a = CInt( Rnd * 10 ) + 1
if a > 10 then a = 1
loc = specchars
tmp = tmp & Mid( loc, a, 1 )
Redim wordarray( length )
for i = 1 to len( tmp )
wordarray( i - 1 ) = Mid( tmp, i, 1 )
next
tmp = ""
for i = 0 to ubound( wordarray ) step 2
if i > ubound( wordarray ) then exit for
tmp = tmp & wordarray( i )
next
for i = 1 to ubound( wordarray ) step 2
if i > ubound( wordarray ) then exit for
tmp = tmp & wordarray( i )
next
MkPassword = cstr( strReverse( tmp ) )
End Function
%>

This snippet checks for strong passwords when the user enters it -

<%
Class StrongPwd
Private AllChars, sFailure

Private Sub Class_Initialize()
Dim s

s = ""
s = s & "A>=a{Bn0@Cb;D[o1<Ecp~F2qG}rH/d%3(st^IJ]eu"
s = s & "$4K:Lf5&M*v-gN`6?OhP+| 7w)iQ""\R8jS.xT9_kUy'VW,lXm!#YzZ"
AllChars = s
End Sub

Public Function Create()
Dim hPwdLen, i, sOut, sNewOut, hBeg, hEnd

hBeg = 0
hEnd = 0
hPwdLen = 0
i = 0
sOut = ""
sNewOut = ""

Randomize
hPwdLen = int((rnd * 10) + 7)
for i = 1 to hPwdLen
Randomize
sOut = sOut & mid(AllChars, int(rnd * len(AllChars)) + 1, 1)
next
hEnd = len(sOut) - 1
do until (hBeg = hEnd) or (hEnd - 1 = hBeg)
sNewOut = sNewOut & mid(sOut, hBeg + 1, 1) & mid(sOut, hEnd + 1, 1)
if hBeg = hEnd or hEnd - 1 = hBeg then exit do
hEnd = abs(hEnd - 1)
hBeg = abs(hBeg + 1)
loop
if hPwdLen mod 2 = 0 then
sNewOut = sNewOut & mid(sOut, hBeg + 1, 1) & mid(sOut, hEnd + 1, 1)
else
sNewOut = sNewOut & mid(sOut, hBeg + 1, 1)
end if
Create = strReverse(sNewOut)
End Function

Public Function CreateEx()
dim sPwd

sPwd = create
do until check("anonymous", sPwd)
sPwd = create
loop
CreateEx = sPwd
End Function

Public Property Get FailurePoint
FailurePoint = sFailure
End Property

Public Function Check(ByVal sUsrName, ByVal sPassword)
'http://support.microsoft.com/support/kb/articles/q161/9/90.asp
Dim re, passCt

sFailure = ""
Check = false
passCt = 0

'Passwords must be at least six (6) characters long
if len(sPassword) < 6 then
sFailure = "minimum length requirement not satisfied"
Exit Function
end if

'Passwords may not contain your user name
if instr(lcase(sPassword), lcase(sUsrName)) <> 0 then
sFailure = "password contains user name"
Exit Function
end if

'Passwords must contain characters from at least three (3)
'of four (4) character classes
set re = new regexp
With re
.ignorecase = false
.global = true
.multiline = false
.pattern = "[A-Z_]"
if .test(sPassword) then
passCt = passCt + 1
else
sFailure = "Missing character class: " & _
"English upper case letters" & vbcrlf
end if
.pattern = "[a-z_]"
if .test(sPassword) then
passCt = passCt + 1
else
sFailure = sFailure & "Missing character class: " & _
"English lower case letters" & vbcrlf
end if
.pattern = "[0-9]"
if .test(sPassword) then
passCt = passCt + 1
else
sFailure = sFailure & "Missing character class: " & _
"Westernized arabic numbers" & vbcrlf
end if
.pattern = "[\W]"
if .test(sPassword) then
passCt = passCt + 1
else
sFailure = sFailure & "Missing character class: " & _
"Non-alphanumeric (""special characters"")" & vbcrlf
end if
End With
set re = nothing
if passCt < 3 then Exit Function
sFailure = ""
Check = True
End Function
End Class
%>


Thanks for any help.
Back to top
View user's profile Send private message Send e-mail
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Feb 11th, 2004 10:51 AM    Post subject: Reply with quote

Hi!

This is not a VB page its an ASP script.

Thanks!
_________________
Code Snippets, Tutorials, Utilities, Controls

Low cost Web Hosting
Hosting starts at as low as $4 per year!


Always follow posting guidelines
Put your VB code in [vb ] your code [ /vb] tags!
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
ammo325
Newbie


Joined: 10 Feb 2004
Posts: 5

PostPosted: Feb 11th, 2004 11:08 AM    Post subject: Reply with quote

Thanks. I thought they ASP was a derivitive of VB
Back to top
View user's profile Send private message Send e-mail
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Feb 11th, 2004 11:18 AM    Post subject: Reply with quote

Hi!

ASP requires IIS and VB does not. Though if you have provision of IIS then these scripts can be customized to use with your VB program.

If you need any help regarding that then please don't hesitate to post!

Thanks!
_________________
Code Snippets, Tutorials, Utilities, Controls

Low cost Web Hosting
Hosting starts at as low as $4 per year!


Always follow posting guidelines
Put your VB code in [vb ] your code [ /vb] tags!
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
ammo325
Newbie


Joined: 10 Feb 2004
Posts: 5

PostPosted: Feb 11th, 2004 11:46 AM    Post subject: Reply with quote

Thanks for the reply. I am not asking anyone to write any script for me or anything. A nudge in the right direction would suffice.

I have taken two classes in VB and have a book. However that doesn't help too much when I don't know where to start.


Any help would be appreciated.
Back to top
View user's profile Send private message Send e-mail
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Feb 11th, 2004 11:53 AM    Post subject: Reply with quote

Hi!

You just tell us ...what type of help you need. Just post it in the appropriate section and we'll post a reply asap.

Thanks!
_________________
Code Snippets, Tutorials, Utilities, Controls

Low cost Web Hosting
Hosting starts at as low as $4 per year!


Always follow posting guidelines
Put your VB code in [vb ] your code [ /vb] tags!
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
ammo325
Newbie


Joined: 10 Feb 2004
Posts: 5

PostPosted: Feb 11th, 2004 02:40 PM    Post subject: Reply with quote

Thanks. I guess the main question I have is in the login script when it starts to look for a user entered password:

'check password
If objRS("password")=Request.Form("password") Then
'username/password valid
'save session data
Session("loggedin") = True
Session("userid") = objRS("id")
'redirect to members area
Response.Redirect ("default.asp")
Response.End

How do I have the script refer to the strong password snippet:

<%
Class StrongPwd
Private AllChars, sFailure

Private Sub Class_Initialize()
Dim s

s = ""
s = s & "A>=a{Bn0@Cb;D[o1<Ecp~F2qG}rH/d%3(st^IJ]eu"
s = s & "$4K:Lf5&M*v-gN`6?OhP+| 7w)iQ""\R8jS.xT9_kUy'VW,lXm!#YzZ"
AllChars = s
End Sub

Public Function Create()
Dim hPwdLen, i, sOut, sNewOut, hBeg, hEnd

hBeg = 0
hEnd = 0
hPwdLen = 0
i = 0
sOut = ""
sNewOut = ""

Randomize
hPwdLen = int((rnd * 10) + 7)
for i = 1 to hPwdLen
Randomize
sOut = sOut & mid(AllChars, int(rnd * len(AllChars)) + 1, 1)
next
hEnd = len(sOut) - 1
do until (hBeg = hEnd) or (hEnd - 1 = hBeg)
sNewOut = sNewOut & mid(sOut, hBeg + 1, 1) & mid(sOut, hEnd + 1, 1)
if hBeg = hEnd or hEnd - 1 = hBeg then exit do
hEnd = abs(hEnd - 1)
hBeg = abs(hBeg + 1)
loop
if hPwdLen mod 2 = 0 then
sNewOut = sNewOut & mid(sOut, hBeg + 1, 1) & mid(sOut, hEnd + 1, 1)
else
sNewOut = sNewOut & mid(sOut, hBeg + 1, 1)
end if
Create = strReverse(sNewOut)
End Function

Public Function CreateEx()
dim sPwd

sPwd = create
do until check("anonymous", sPwd)
sPwd = create
loop
CreateEx = sPwd
End Function

Public Property Get FailurePoint
FailurePoint = sFailure
End Property

Public Function Check(ByVal sUsrName, ByVal sPassword)
'http://support.microsoft.com/support/kb/articles/q161/9/90.asp
Dim re, passCt

sFailure = ""
Check = false
passCt = 0

'Passwords must be at least six (6) characters long
if len(sPassword) < 6 then
sFailure = "minimum length requirement not satisfied"
Exit Function
end if

'Passwords may not contain your user name
if instr(lcase(sPassword), lcase(sUsrName)) <> 0 then
sFailure = "password contains user name"
Exit Function
end if

'Passwords must contain characters from at least three (3)
'of four (4) character classes
set re = new regexp
With re
.ignorecase = false
.global = true
.multiline = false
.pattern = "[A-Z_]"
if .test(sPassword) then
passCt = passCt + 1
else
sFailure = "Missing character class: " & _
"English upper case letters" & vbcrlf
end if
.pattern = "[a-z_]"
if .test(sPassword) then
passCt = passCt + 1
else
sFailure = sFailure & "Missing character class: " & _
"English lower case letters" & vbcrlf
end if
.pattern = "[0-9]"
if .test(sPassword) then
passCt = passCt + 1
else
sFailure = sFailure & "Missing character class: " & _
"Westernized arabic numbers" & vbcrlf
end if
.pattern = "[\W]"
if .test(sPassword) then
passCt = passCt + 1
else
sFailure = sFailure & "Missing character class: " & _
"Non-alphanumeric (""special characters"")" & vbcrlf
end if
End With
set re = nothing
if passCt < 3 then Exit Function
sFailure = ""
Check = True
End Function
End Class
%>
Back to top
View user's profile Send private message Send e-mail
ammo325
Newbie


Joined: 10 Feb 2004
Posts: 5

PostPosted: Feb 12th, 2004 02:59 PM    Post subject: Reply with quote

Any takers on this?
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Other Languages All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic