//validates an auth code public static bool IsGoodAuthCode(string authCode) { Contract.Requires(!string.IsNullOrWhiteSpace(authCode)); var log = ClassLogger.Create(typeof(AuthorizationCode)); var dblog = DebugOnlyLogger.Create(log); try { var plain = DecryptCode(authCode); dblog.InfoFormat(DecryptedAuthCodeFormat, plain); var parts = plain.Split(Separator); if (parts.Length != 2) { log.ErrorFormat(AuthCodeFailedFormat, plain); return(false); } var goodGuid = GuidEncoder.Decode(parts[0]); if (Guid.Empty != goodGuid && parts[1].Contains(_magic)) { dblog.InfoFormat(AuthCodeAuthorizedFormat, plain); return(true); } //when not in right format log.ErrorFormat(AuthCodeFailedFormat, plain); return(false); } catch (Exception exception) { log.Error("IsGoodAuthCode", exception); log.ErrorFormat(AuthCodeFailedFormat, authCode); return(false); } }
public static string GenerateCode() { var plainText = string.Format("{0}|{1}", GuidEncoder.Encode(Guid.NewGuid()), _magic); return(GenerateCode(plainText)); }