Example #1
0
 public bool Equals(GitCommit other)
 {
     return(Hashcode.Equals(other.Hashcode) &&
            Username.Equals(other.Username) &&
            Description.Equals(other.Description) &&
            Date.Equals(other.Date));
 }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="isActive">Is the user session enabled.</param>
        /// <param name="userIdentityName">The user identity name for the current user.</param>
        /// <param name="userSessionData">The session state data for the user.</param>
        public UserOnlineController(bool isActive, string userIdentityName, Object userSessionData)
        {
            if (userIdentityName == null)
            {
                throw new ArgumentNullException("userIdentityName");
            }

            _isActive         = isActive;
            _userSessionData  = userSessionData;
            _userIdentityName = userIdentityName;
            _uniqueHashcode   = Hashcode.GetHashcode(userIdentityName, HashcodeType.SHA512);
        }
Example #3
0
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            // Write your Authentication code here
            IEnumerable <string> sampleApiKeyHeaderValues = request.Headers.GetValues("AuthenticateApi");
            Hashcode             hashcode = new Hashcode();
            var hashCodeEncrypt           = hashcode.Encrypt("Fb!$5687");

            // Checking the Header values
            if (sampleApiKeyHeaderValues.Any())
            {
                string[] apiKeyHeaderValue = sampleApiKeyHeaderValues.First().Split(new char[] { ':' }, 2);

                // Validating header value must have both APP ID & APP key
                if (apiKeyHeaderValue.Length == 2)
                {
                    // Code logic after authenciate the application.
                    var apiKey   = apiKeyHeaderValue[0];
                    var hashCode = apiKeyHeaderValue[1];

                    if (apiKey.Equals("SevaXSindhu89674523") && hashCode.Equals(hashCodeEncrypt))
                    {
                        var userNameClaim = new Claim(ClaimTypes.Name, hashCode);
                        var identity      = new ClaimsIdentity(new[] { userNameClaim }, "SampleAppApiKey");
                        var principal     = new ClaimsPrincipal(identity);
                        Thread.CurrentPrincipal = principal;

                        if (System.Web.HttpContext.Current != null)
                        {
                            System.Web.HttpContext.Current.User = principal;
                        }
                    }
                    else
                    {
                        // Web request cancel reason APP key is NULL
                        return(requestCancel(request, cancellationToken, InvalidToken));
                    }
                }
                else
                {
                    // Web request cancel reason missing APP key or APP ID
                    return(requestCancel(request, cancellationToken, MissingToken));
                }
            }
            else
            {
                // Web request cancel reason APP key missing all parameters
                return(requestCancel(request, cancellationToken, MissingToken));
            }

            return(base.SendAsync(request, cancellationToken));
        }
Example #4
0
        public override Dictionary <string, object> SaveToDict()
        {
            var dict = new Dictionary <string, object>();

            dict.Add(GDMConstants.SchemaKey, "Rune");

            dict.Merge(true, locked.ToGDEDict(lockedKey));
            dict.Merge(true, Hashcode.ToGDEDict(HashcodeKey));
            dict.Merge(true, posInOwner.ToGDEDict(posInOwnerKey));
            dict.Merge(true, quality.ToGDEDict(qualityKey));
            dict.Merge(true, star.ToGDEDict(starKey));
            dict.Merge(true, level.ToGDEDict(levelKey));
            dict.Merge(true, initalQuality.ToGDEDict(initalQualityKey));
            dict.Merge(true, id.ToGDEDict(idKey));
            dict.Merge(true, ownerId.ToGDEDict(ownerIdKey));

            dict.Merge(true, attitube.ToGDEDict(attitubeKey));
            return(dict);
        }
Example #5
0
        private void OnAuthenticateRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext     context     = application.Context;
            HttpRequest     request     = context.Request;
            HttpResponse    response    = context.Response;

            try
            {
                // Create a new member info type.
                MemberInfo memberInfo = new MemberInfo();

                // Has the user been authenticated
                if (request.IsAuthenticated)
                {
                    // Get the user identity name
                    string userIdentityName = context.User.Identity.Name;

                    // Generate the hash code from the user identity name.
                    memberInfo.UniqueHashcode   = Hashcode.GetHashcode(userIdentityName, HashcodeType.SHA512);
                    memberInfo.UserIdentityName = userIdentityName;

                    // Add the member info to the context collection.
                    if (((MemberInfo)context.Items[memberInfo.UniqueHashcode]) == null)
                    {
                        context.Items.Add(memberInfo.UniqueHashcode, memberInfo);
                    }

                    // Add the new item or set the current member info.
                    Nequeo.Caching.RuntimeCache.Set(memberInfo.UniqueHashcode, memberInfo, (double)600.0);
                }
                else
                {
                    // The user has not been authenticated
                    // the connecting user is anonymous.
                    string userIdentityName = request.AnonymousID;

                    // If no anonymous id is found then
                    // generate a random user idnetity name.
                    if (String.IsNullOrEmpty(userIdentityName))
                    {
                        LowerUpperCaseGenerator password = new LowerUpperCaseGenerator();
                        userIdentityName           = password.Random(30, 30);
                        memberInfo.IsAnonymousUser = true;
                        memberInfo.HasAnonymousID  = false;
                    }
                    else
                    {
                        memberInfo.IsAnonymousUser = true;
                    }

                    // Generate the hash code from the user identity name.
                    memberInfo.UniqueHashcode   = Hashcode.GetHashcode(userIdentityName, HashcodeType.SHA512);
                    memberInfo.UserIdentityName = userIdentityName;

                    // Add the member info to the context collection.
                    if (((MemberInfo)context.Items[memberInfo.UniqueHashcode]) == null)
                    {
                        context.Items.Add(memberInfo.UniqueHashcode, memberInfo);
                    }

                    // Add the new item or set the current member info.
                    Nequeo.Caching.RuntimeCache.Set(memberInfo.UniqueHashcode, memberInfo, (double)600.0);
                }
            }
            catch (Exception ex)
            {
                context.AddError(ex);
                LogHandler.WriteTypeMessage(ex.Message, typeof(Membership).GetMethod("OnAuthenticateRequest"));
            }
        }