-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathHardcodedCredentials.cs
More file actions
31 lines (25 loc) · 930 Bytes
/
HardcodedCredentials.cs
File metadata and controls
31 lines (25 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using Microsoft.AspNet.Identity;
using System;
using System.Web;
using System.Web.Security;
public class HardCodedCredentialHandler : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
string password = ctx.Request.QueryString["password"];
// BAD: Inbound authentication made by comparison to string literal
if (password == "myPa55word")
{
ctx.Response.Redirect("login");
}
string hashedPassword = loadPasswordFromSecretConfig();
// GOOD: Inbound authentication made by comparing to a hash password from a config
if (PasswordHasher.VerifyHashedPassword(hashedPassword, password))
{
ctx.Response.Redirect(VALID_REDIRECT);
}
// BAD: Set the password to a hardcoded string literal
MembershipUser user = loadMembershipUser();
user.ChangePassword(password, "myNewPa55word");
}
}