I am looking to protect a cloud page with a login page. i have written this SSJS for the page to be secured:
<html>
<head>
<script runat="server">
Platform.Load("Core", "1");
var username = Request.GetFormField("username");
var password = Request.GetFormField("password");
var allowedUsername = "your_username";
var allowedPassword = "your_password";
if (username != allowedUsername || password != allowedPassword) {
Platform.Response.Redirect(CloudPagesURL(pageID));
}
</script>
</head>
<body>
<!-- Protected content -->
and on the login page:
<html>
<head>
<style>
.container {
width: 100%;
max-width: 360px;
margin: 0 auto;
padding: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Login</h1>
<form id="login-form" method="POST" action="%%=CloudPagesURL(protectedpageID)=%%">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username" required><br><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password" required><br><br>
<input type="submit" value="Login">
</form>
</div>
</body>
</html>
I get a 500 error on the page that I want to be secured. Not sure what I am missing.