Can you find the bug in this code?
This is a real bug that I came across yesterday in some code I had written about a week before. I was a little surprised at the mechanics but it makes sense once you understand what is happening ...
1: private void Foo()
2: {
3: try
4: {
5: AuthenticationInfo authenticationInfo = GetAuthenticationInfo(Request.QueryString["t"]);
6: Authenticator authenticator = new Authenticator(new LoginProvider());
7: AuthenticationStatus authenticationStatus = authenticator.Authenticate(authenticationInfo);
8: if (authenticationStatus.Authenticated)
9: {
10: IUser user =
11: BLUser.Load(authenticationInfo.UserName, authenticationInfo.OrganizationCode, authenticationInfo.DomainId);
12: user.SetNewSessionId();
13: AuthenticationTokenParser authenticationTokenParser = new AuthenticationTokenParser();
14: string authenticationToken = authenticationTokenParser.Create(user.UserName, user.OrganizationId, user.DomainId);
15: FormsAuthentication.SetAuthCookie(authenticationToken, true);
16: string redirectUrl = FormsAuthentication.GetRedirectUrl(authenticationToken, true);
17: if (redirectUrl == null || redirectUrl.Trim().Length == 0)
18: {
19: redirectUrl = "~/Home.aspx";
20: }
21: Response.Redirect(redirectUrl, true);
22: }
23: Response.Redirect("~/Home.aspx");
24: }
25: catch
26: {
27: Response.Redirect("~/Home.aspx");
28: }
29: }
I will post the answer soon if no-one gets it. :)
Jonathan Cogley is the CEO and founder of Thycotic Software, a .NET consulting company and ISV in Washington DC. Our product, Secret Server is a enterprise password manager system for teams to secure their passwords. Is your team still storing passwords in a text file?