public static bool TryParseEmailVerificationString(string value, out Guid userId, out string verificationCode) { userId = Guid.Empty; verificationCode = string.Empty; if (string.IsNullOrWhiteSpace(value)) { return(false); } value = value.Replace("-", "/").Replace("_", "+"); string s = Decrypt(value); if (string.IsNullOrWhiteSpace(s)) { return(false); } string[] sections = s.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (sections.Length != 4) { return(false); } userId = IDConverter.Decode(sections[1]); verificationCode = sections[2]; return(userId != Guid.Empty && !string.IsNullOrEmpty(verificationCode)); }
public T ConvertTo <T>() where T : new() { if (this.Request != null) { //enforce UserId in the target object before serialization switch (this.Mode) { case AuthenticationMode.UserCookie: if (!this.Request.ContainsKey("UserId")) { this.Request.Add("UserId", IDConverter.Encode(this.UserId)); } else { this.Request["UserId"] = IDConverter.Encode(this.UserId); } break; case AuthenticationMode.API: if (this.Request.ContainsKey("UserId")) { this.UserId = IDConverter.Decode(this.Request["UserId"].ToString()); } break; } return(this.Request.ToObject <T>()); } return(new T()); }
public static string BuildEmailVerificationString(Guid userId, string verificationCode) { var s = string.Join("|", DateTime.UtcNow.Ticks, IDConverter.Encode(userId), verificationCode, DateTime.UtcNow.AddYears(-20).Ticks); s = Encrypt(s); return(s.Replace("/", "-").Replace("+", "_")); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => reader.TokenType == JsonToken.Null ? null : reader.TokenType != JsonToken.String ? null : (object)IDConverter.Decode(reader.Value.ToString());
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => writer.WriteValue(IDConverter.Encode((Guid)value));
public static Guid Decode(this string id) => IDConverter.Decode(id);
public static string Encode(this Guid id) => IDConverter.Encode(id);