 |
| ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 13th, 2006, 04:46 PM
|
|
|
Array question
Hi,
Please recommend the best method to accomplish the following. I've been reading different postings and am now confused!
I have like to parse an input string (character by character) and compare the characters to the following array:
Dim new_variable
Dim LAlphaArray() As String = {"a","b","c","d","e","f","g","h","i","j","k","l"," m","n","o","p","q","
r","s","t","u","v","w","x","y","z"};
I thought it should go something like this:
for intCtr= 1 to len(new_variable)
charArray(intCtr - 1) = Mid(new_variable, intCtr, 1);
Next
But I'm wondering if using 'split' with no options would be best to move thru the new_variable field character by character. Then would I use split w/the comma option to move thru the LAlphaArray? If possible, please include coding examples w/any suggestions.
Thanks!
|
|

June 13th, 2006, 06:18 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
You might be better off using a regular expression test. What would be the results of comparing characters? What action would be taken with the character after the comparison?
|
|

June 14th, 2006, 01:54 PM
|
|
|
I have to verify that the new_variable contains both Upper and Lower case characters and then a numeric and a special character. This is actually a password which I am testing for compliancy. There are many other rules associated with the password. I was thinking of using an array and then looping thru for each test where I would set a switch once the test was passed. If all tests are passed, the password is compliant.
|
|

June 14th, 2006, 02:27 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
This can be done using regular expressions without doing so much hard programming... and thinking. Please check into that. There are many regular expression examples on the net that can be modified to what you need.
This password test must have at least one number, one letter, one of those special characters and must be 8 to 15 characters long. Easy?
Function CheckPassword(ByVal Value As String) As Boolean
Dim ex As Regex = New Regex("^(?=.*[\d])(?=\w*[a-z])(?=.*[!@#$&*]).{8,15}")
Return ex.Match(Value).Success
End Function
|
|

June 14th, 2006, 02:33 PM
|
|
|
Looks a lot easier than the array functions I would have tried. Thanks! I'll try your suggestion.
|
|

June 14th, 2006, 04:28 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Hah... cool.. let me know how it works out.
|
|

June 19th, 2006, 03:44 PM
|
|
|
I cannot get the page to display since adding the function to it.
I've tried accessing other p2p pages for information but have not been able to find any.
The error message I receive is that the variable 'CheckPassword' is undefined. I've tried numerous changes but have not been able to get it working.
Any assistance you can lend me would be appreciated.
Thanks!
|
|

June 19th, 2006, 04:58 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Put this in a Try. Should work. If you get any error, post it here and I'll try to figure out what it is.
Code:
'Set this string = to whatever your password field is. You probably already know that.
Dim strPassword As String = txtUserPass.Text
Dim ex As Regex = New Regex("^(?=.*[\d])(?=\w*[a-z])(?=.*[!@#$&*]).{8,15}")
If ex.Match(strPassword).Success = False Then
Throw New Exception("Please provide a valid password that contains at least one letter, one number, one of these special characters !@#$&* and is between 8 and 15 characters.")
End If
|
|

June 20th, 2006, 09:02 AM
|
|
|
Thanks for responding; I do appreciate your assistance.
Here is the code (entire page but it isn't too large). I am still receiving the same error "Variable is undefined: 'CheckPassword' "
<% @language="vbscript" %>
<% option explicit %>
<%
'
'************************************
'Description - Validate and update password.
'Inputs â Username, old password, new password.
'Permanent Test Files - none
'Outputs â none
'Interfaces with other applications or programs - None
'Environments â Windows Server 2003, ASP.Net, VBScript
'
'Change Log:
'Change Date â
'Change Doc # -
'Version 1.1
'Programmer Name â
'Description -
%>
<%
'Declare all variables
Dim strUsername, strPassword, strSysName, strInstance
Dim strAccessKey, strnewPassword, strConfirmPassword, strOldPassword, newPassword
Dim oConn, oRst, mySQL
'If there is an error continue on the next line - comment next line for debugging
'On Error Resume Next
'Get the passed form variables and set other variables
strUsername = Request.Form("Username")
strPassword = Request.Form("Password")
strSysName = Request.Form("strSysName")
strAccessKey = "ScanApp%"
strNewPassword = Request.Form("NewPassword")
strOldPassword = Request.Form("OldPassword")
strConfirmPassword = Request.Form("ConfirmPassword")
%>
<html>
<script>
Function CheckPassword(ByVal newPassword As String) As Boolean
'Set strPassword = to whatever your password field is.
Dim strPassword As String = newPassword.Text
Dim ex As Regex = New
Regex("^(?=.*[\d])(?=\w*[a-z])(?=.*[!@#$&*]).{8,15}")
If ex.Match(strPassword).Success = False Then
Throw New Exception("Please provide a valid password that contains at
least one letter, one number, one of these special characters !@#$&* and
is between 8 and 15 characters.")
End If
End Function
</script>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Password Reset</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<%
'verify that new password and reentered new password are same.
'Create the connection object
Set oConn = Server.CreateObject("ADODB.Connection")
'Set the connection string and open the connection
oConn.ConnectionString = "Provider=MSDAORA.1;User ID=" & strUsername & ";Password=" & strPassword & ";Data
Source=" & strInstance
oConn.Open
'Create the recordset using the SQL statement
Set oRst = Server.CreateObject("ADODB.Recordset")
If strNewPassword = strConfirmPassword THEN
'verify that password meets criteria
CheckPassword strNewPassword
'UID Database table SQL Code after making sure a record exists
mySQL = "SELECT count(*) as strCount"
mySQL = mySQL & " FROM test_table"
mySQL = mySQL & " WHERE USERID = '" & strUsername & "'AND"
mySQL = mySQL & " PASSWORD = '" & strOldPassword & "'AND"
mySQL = mySQL & " ROLES like '" & strAccessKey & "' "
'Create the record using the SQL statement
Set oRst = oConn.Execute(mySQL)
If Len(Err.Description) > 0 Then
Err.Description = "Data not valid. Please re-enter."
Set oConn = Nothing
End If
IF (oRst.Fields("strCount").value > "0") THEN
mySQL = "UPDATE test_table"
mySQL = mySQL & " SET Password = '" & strNewPassword & "' "
mySQL = mySQL & " WHERE USERID = '" & strUsername & "'AND"
mySQL = mySQL & " PASSWORD = '" & strOldPassword & "'AND"
mySQL = mySQL & " ROLES like '" & strAccessKey & "' "
'Update the record using the SQL statement
oConn.Execute(mySQL)
If Len(Err.Description) > 0 Then
Err.Description = "Former password error. Please re-enter."
Set oConn = Nothing
ELSE
Err.Description = "Password Reset!"
End If
ELSE
Err.Description = "Data not valid. Please re-enter."
Set oConn = Nothing
END IF
Response.Write "<br>mySQL : " + mySQL
On Error Resume Next
'Close the connection
oConn.Close()
Set oConn = Nothing
ELSE
Err.Description = "New passwords not validated. Please re-enter."
END IF
%>
<table width="100%">
<tr>
<td colspan="2" align="center">
</td>
</tr>
<tr>
<td width="10%" height="100%" bgcolor="#003399" valign="top">
</td>
<td width="90%" align="center">
<form name="myForm" method="POST" action="perform_delete_All.asp">
<%
Response.Write "<p>" & Err.Description & "</p>"
Response.Write "<p><a href=""javascript:history.back(1)"">Back</a></p>"
%>
<table>
<tr align="center">
<td align="center">
<input type="button" value="Main Menu" name="MainMenu" onClick="main_menu(document
.myForm)"><br>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<tr>
<td colspan="2" align="center" >
</td>
</tr>
</body>
</html>
|
|

June 20th, 2006, 05:49 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
The function "CheckPassword()" is written in VB.NET. I don't think it will work the same in classic ASP. I was just thrown off a little since this is a .NET forum.
If you're going to use classic ASP you easily use a regular expression test in javascript. I'm getting this late in the day and don't have time to post it right now. But I will post tomorrow.
|
|
 |