Some ASP small source program

Source: Internet
Author: User
Tags chr dsn regular expression
Active Server Pages
Password Script
<%
Sub forminput ()%>
<form method=post action= "Logon.asp" >
<center>
User name:<input type=text size=20 name=username>
<br><br>
Password:<input Type=password size=20 name=password>
<br><br>
<input type=submit name=submit value= "Submit" >
</center>
</form>
<% End Sub%>
<!--#include file= "Adovbs.inc"-->

<%
' *********** Password Login Code *********************
' *********** programmed by Robert Robbins ************
' *********** ' 03/28/99 ******************
' *****************************************************
' Call Input Form subroutine
Forminput ()

' Create session variable. Username needed for filename.asp
Session ("user") = ""

' Initialize Boolean flags to False
Correct_name = False
Correct_password = False

' Connect to table in database
Set cn = Server.CreateObject ("ADODB.") Connection ")
Set rs = Server.CreateObject ("ADODB.") Recordset ")
cn. Open "DSN Name"
Rs. Open "SELECT * FROM tablename", cn,adopenstatic,adlockpessimistic

' Test for correct username and password
If Request.Form ("submit") > "Then
Do but not Rs. Eof
' Compare form input to password database recordset values
If Request.Form ("username") = RS ("username") Then
Correct_name = True
End If
If request.form ("password") = rs ("password") Then
Correct_password = True
End If
Rs. MoveNext
Loop

If Correct_password = True and Correct_name = True Then
' If password and username are correct, jump to dataentry.asp
' NOTE:CHR ' is the double quotes character
Session ("user") = Request.Form ("username")
Response.Write "<script language=" & Chr (+) & "JavaScript" & Chr (+) & ">"
Response.Write "window.location =" & Chr (+) & "dataentry.asp" & Chr (+) & ""
Response.Write "</Script>"
Else
' If password or username is incorrect, write JavaScript code in HTML for an alert
dialog box
Response.Write "<script language=" & Chr (+) & "JavaScript" & Chr (+) & ">"
Response.Write "Alert (" & CHR) & "Access denied!" & Chr (+) &);
Response.Write "</Script>"
End If
Rs. Close
End If
%>
Password Protect Script
<%
' Set local variable username to session variable user
Username = Session ("User")

' If username is a empty string, the user did not use Logon.asp to login
If username = "" Then
Response.Write "Sorry, are not logged in!<br>"
Session.Abandon
Response.End
End If
%>
Email Script
NewLine = Chr (+) & Chr (10)
Set Mailer = Server.CreateObject ("CDONTS. NewMail ")
Mailer.to = "" & Request.Form ("Email") & ""
Mailer.from = "" & "Rrobbins@sunlink.net" & ""
Mailer.subject = "" & "Testing Automated Email" & ""
Mailer.body = "" & "my email message" & newline & "Second line" & "
Mailer.send
Set Mailer = Nothing
SQL Server Connection
<%
Set cn = Server.CreateObject ("ADODB.") Connection ")
Set rs = Server.CreateObject ("ADODB.") Recordset ")
strconn = "Driver={sql server};server=pentium;uid=sa;pwd=;d atabase=test"
cn. Open strconn
%>
Windows Script Host
' Windows Script Host File
' Programmed by Robert S. Robbins
' Open database connecection and get recordset
Const adopenforwardonly = 0
Const adlockpessimistic = 2
Set cn = WScript.CreateObject ("ADODB.") Connection ")
Set rs = WScript.CreateObject ("ADODB.") Recordset ")
cn. Open "DSN Name"
Rs. Open "SELECT * FROM tablename", cn,adopenforwardonly,adlockpessimistic
While not Rs. Eof
message = RS (' message ')
MsgBox message,64, "Database message"
Rs. MoveNext
Wend

VBScript 5.0 Regular Expression
<%
Set objfile = Server.CreateObject ("Scripting.FileSystemObject")
Set inFile = Objfile.opentextfile ("D:\Temp\test.txt", 1)
Strinput = Infile.readall
Infile.close
Set myTest = new REGEXP
Mytest.pattern = "\w+,"
Mytest.global = True
Mytest.ignorecase = True
Set mycollection = Mytest.execute (strinput)
For each element in mycollection
Response.Write Element & "<BR>"
Next
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.