fork download
  1. #importing CGI library
  2. import cgi
  3.  
  4. # Set up HTML header
  5. print("Content-Type: text/html")
  6. print() # Blank line separating headers from the body
  7.  
  8. # Get form data
  9. form = cgi.FieldStorage()
  10. username = form.getvalue('username')
  11. password = form.getvalue('password')
  12.  
  13. # Sample username and password for validation
  14. valid_username = "user123"
  15. valid_password = "pass123"
  16.  
  17. # Begin HTML output
  18. print("<html>")
  19. print("<head>")
  20. print("<title>Login Result</title>")
  21. print("</head>")
  22. print("<body>")
  23.  
  24. #
  25. if username and password:
  26. if username == valid_username and password == valid_password:
  27. print(f"<h2>Welcome, {username}!</h2>")
  28. print("<p>Login successful.</p>")
  29. else:
  30. print("<h2>Login Failed!</h2>")
  31. print("<p>Incorrect username or password.</p>")
  32. else:
  33. print("<h2>Error!</h2>")
  34. print("<p>Please enter both username and password.</p>")
  35.  
  36. print("</body>")
  37. print("</html>")
  38.  
Success #stdin #stdout 0.06s 12604KB
stdin
Standard input is empty
stdout
Content-Type: text/html

<html>
<head>
<title>Login Result</title>
</head>
<body>
<h2>Error!</h2>
<p>Please enter both username and password.</p>
</body>
</html>