Sample Applications

Here are several self-contained, working sample applications that demonstrate ASPPY's native modules. You can copy these files into your environment and try them out immediately.

An interactive page where users can input text to see the generated bcrypt hash, and then input a hash to verify it natively.

<%@ Language="VBScript" %>
<%
Dim textToHash, hashResult, verified, verifyClass
textToHash = Request.Form("textToHash")
hashResult = ""
verified = ""
verifyClass = ""

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    If Request.Form("action") = "hash" And textToHash <> "" Then
        ' Hash the text using bcrypt (cost 10)
        hashResult = ASPPY.crypto.Hash(textToHash, 10)
    ElseIf Request.Form("action") = "verify" And Request.Form("hashToVerify") <> "" And textToHash <> "" Then
        ' Verify the hash
        If ASPPY.crypto.Verify(textToHash, Request.Form("hashToVerify")) Then
            verified = "Match! The text corresponds to the hash."
            verifyClass = "alert-success"
        Else
            verified = "No match! The text does not correspond to the hash."
            verifyClass = "alert-danger"
        End If
    End If
End If
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ASPPY Crypto App</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container mt-5" style="max-width: 600px;">
    <div class="card shadow-sm mb-4">
        <div class="card-header bg-dark text-white"><h4>Password Hasher (bcrypt)</h4></div>
        <div class="card-body">
            <form method="post" action="test_hasher.asp">
                <input type="hidden" name="action" value="hash">
                <div class="mb-3">
                    <label class="form-label">Plain Text Password</label>
                    <input type="text" name="textToHash" class="form-control" value="<%=Server.HTMLEncode(textToHash)%>" required>
                </div>
                <button type="submit" class="btn btn-primary w-100">Generate Hash</button>
            </form>
            <% If hashResult <> "" Then %>
                <div class="mt-4">
                    <label class="form-label text-muted">Generated Hash:</label>
                    <div class="alert alert-secondary text-break" style="font-family: monospace;">
                        <%=Server.HTMLEncode(hashResult)%>
                    </div>
                </div>
            <% End If %>
        </div>
    </div>
    
    <div class="card shadow-sm">
        <div class="card-header bg-secondary text-white"><h4>Verify Hash</h4></div>
        <div class="card-body">
            <% If verified <> "" Then %>
                <div class="alert <%=verifyClass%>"><%=verified%></div>
            <% End If %>
            <form method="post" action="test_hasher.asp">
                <input type="hidden" name="action" value="verify">
                <div class="mb-3">
                    <label class="form-label">Plain Text</label>
                    <input type="text" name="textToHash" class="form-control" value="<%=Server.HTMLEncode(textToHash)%>" required>
                </div>
                <div class="mb-3">
                    <label class="form-label">Bcrypt Hash</label>
                    <input type="text" name="hashToVerify" class="form-control" value="<%=Server.HTMLEncode(Request.Form("hashToVerify"))%>" required>
                </div>
                <button type="submit" class="btn btn-success w-100">Verify</button>
            </form>
        </div>
    </div>
</div>
</body>
</html>

An application with a <textarea> where users can enter arbitrary text and generate a styled A4 PDF on the fly. It also provides a download link.

<%@ Language="VBScript" %>
<%
Dim textInput, pdfUrl
textInput = Request.Form("pdfText")
pdfUrl = ""

If Request.ServerVariables("REQUEST_METHOD") = "POST" And textInput <> "" Then
    Dim pdf, fileName, physicalPath
    
    ' Initialize a new A4 PDF
    Set pdf = ASPPY.pdf.New("P", "mm", "A4")
    pdf.add_page()
    
    ' Add a Title
    pdf.set_font "Arial", "B", 24
    pdf.set_text_color 50, 50, 150
    pdf.cell 0, 15, "My Generated PDF", 0, 1, "C"
    pdf.ln 10
    
    ' Add User Text
    pdf.set_font "Arial", "", 12
    pdf.set_text_color 0, 0, 0
    pdf.multi_cell 0, 8, textInput
    
    ' Add a footer timestamp
    pdf.ln 20
    pdf.set_font "Arial", "I", 10
    pdf.set_text_color 150, 150, 150
    pdf.cell 0, 10, "Generated by ASPPY at " & Now(), 0, 1, "R"
    
    ' Create a unique filename based on the current timestamp
    fileName = "generated_" & Replace(Replace(Replace(Now(), "/", ""), ":", ""), " ", "") & ".pdf"
    physicalPath = Server.MapPath("/pdfs/" & fileName)
    
    ' Save and set the download link
    pdf.output physicalPath
    pdfUrl = "/pdfs/" & fileName
End If
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ASPPY PDF Generator</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container mt-5" style="max-width: 600px;">
    <div class="card shadow-sm">
        <div class="card-header bg-danger text-white"><h4>PDF Generator</h4></div>
        <div class="card-body">
            <% If pdfUrl <> "" Then %>
                <div class="alert alert-success text-center">
                    PDF Created Successfully!<br><br>
                    <a href="<%=pdfUrl%>" target="_blank" class="btn btn-sm btn-success">View PDF</a>
                    <a href="<%=pdfUrl%>" download class="btn btn-sm btn-outline-success">Download</a>
                </div>
            <% End If %>
            
            <form method="post" action="test_pdf_app.asp">
                <div class="mb-3">
                    <label class="form-label">Enter text to include in the PDF:</label>
                    <textarea name="pdfText" class="form-control" rows="5" required placeholder="Hello world..."><%=Server.HTMLEncode(textInput)%></textarea>
                </div>
                <button type="submit" class="btn btn-danger w-100">Generate PDF Document</button>
            </form>
        </div>
    </div>
</div>
</body>
</html>

A file uploader application that demonstrates how ASPPY intercepts multipart uploads via Request.Files natively, saves the file, compresses it via ASPPY.zip, and offers it via Response.File for download.

<%@ Language="VBScript" %>
<%
Dim msg, zipPath, download
download = Request.QueryString("download")

If download <> "" Then
    ' Serve the generated zip file natively
    Response.File Server.MapPath("/data/" & download), False
End If

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    If Request.Files.Count > 0 Then
        Dim uploadedFile, savePath, outZip
        Set uploadedFile = Request.Files("fileToZip")
        If Not uploadedFile Is Nothing And uploadedFile.FileName <> "" Then
            savePath = Server.MapPath("/data/" & uploadedFile.FileName)
            uploadedFile.SaveAs savePath

            ' Zip the file
            outZip = Server.MapPath("/data/" & uploadedFile.FileName & ".zip")
            ASPPY.zip.Zip savePath, outZip

            msg = "<div class='alert alert-success'>Successfully compressed! <a href='?download=" & Server.URLEncode(uploadedFile.FileName & ".zip") & "'>Download ZIP</a></div>"
        End If
    End If
End If
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ASPPY Zip Compressor</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container mt-5" style="max-width: 500px;">
    <div class="card shadow-sm">
        <div class="card-header bg-dark text-white"><h4>File to ZIP Compressor</h4></div>
        <div class="card-body">
            <%=msg%>
            <form method="post" action="test_compress.asp" enctype="multipart/form-data">
                <div class="mb-3">
                    <label class="form-label">Select a file to compress:</label>
                    <input class="form-control" type="file" name="fileToZip" required>
                </div>
                <button type="submit" class="btn btn-primary w-100">Upload & Compress</button>
            </form>
        </div>
    </div>
</div>
</body>
</html>