public void GetCredentialsToHash_CredentialObject_ConcatenatedString()
        {
            credentials capitalCredentials = new credentials()
            {
                subject = new subject()
                {
                    subjectType = subjectType.CapitaPortal,
                    identifier  = 174064579
                },
                requestIdentification = new requestIdentification()
                {
                    uniqueReference = "123456",
                    timeStamp       = "20170131125459",
                },
                signature = new signature()
                {
                    algorithm = algorithm.Original,
                    hmacKeyID = 456
                }
            };

            string stringToHash = CapitaApiHelpers.GetCredentialsToHash(capitalCredentials);

            Assert.AreEqual(stringToHash, "CapitaPortal!174064579!123456!20170131125459!Original!456");
        }
        public void CalculateDigest_ValidInput_HashString()
        {
            credentials capitalCredentials = new credentials()
            {
                subject = new subject()
                {
                    subjectType = subjectType.CapitaPortal,
                    identifier  = 174064579
                },
                requestIdentification = new requestIdentification()
                {
                    uniqueReference = "123456",
                    timeStamp       = "20170131125459",
                },
                signature = new signature()
                {
                    algorithm = algorithm.Original,
                    hmacKeyID = 456
                }
            };

            string hmacKey =
                "zgtQwyBsiFkL7ioGpH9YqiYioYpbkQjMmkBrvA6IXGBmzwx+Q5tFn6qbgVgKl95oIiPPHYpWaLquNRWXesBP3w==";

            string stringToHash = CapitaApiHelpers.GetCredentialsToHash(capitalCredentials);
            string hash         = CapitaApiHelpers.CalculateDigest(hmacKey, stringToHash);

            Assert.AreEqual(hash, "X+MlsmdD5RxMQ6/yPaQ0wzJY146oMD0Sp4g3hbXweTU=");
        }
示例#3
0
    private void ValidateLogin()
    {
        showEmailError(" ");
        Password = password.GetComponent <InputField>().text;
        Email    = email.GetComponent <InputField>().text;

        if (Email == null || Email == "" || !Email.Contains("@"))
        {
            showEmailError("Please enter a valid Email address");
        }
        if (Password == null || Password == "")
        {
            showEmailError("Wrong password");
        }
        if (Password.Length < 6)
        {
            showEmailError("Enter a password of atleast 6 digits");
        }
        else
        {
            LoadingCircle.SetActive(true);
            Debug.Log("the email is " + Password + Email);
            //StartCoroutine(CallSendOtp(Email));
        }
        credentials newcred = new credentials();

        newcred.email    = Email;
        newcred.password = Password;
        json             = JsonUtility.ToJson(newcred);
        Debug.Log(json);

        string URL         = "https://api.thedarkhorse.io/api/auth";
        string myAccessKey = "myAccessKey";
        string mySecretKey = "mySecretKey";

        //Auth token for http request
        string accessToken;

        //Our custom Headers

        //Encode the access and secret keys
        accessToken = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(myAccessKey + ":" + mySecretKey));
        //Add the custom headers
        headers.Add("Authorization", "Basic " + accessToken);
        headers.Add("Content-Type", "application/json");
        headers.Add("AnotherHeader", "AnotherData");
        headers.Add("Content-Length", json.Length.ToString());
        //Replace single ' for double "


        //Encode the JSON string into a bytes
        byte[] postData = System.Text.Encoding.UTF8.GetBytes(json);
        //Now we call a new WWW request
        WWW www = new WWW(URL, postData, headers);

        //And we start a new co routine in Unity and wait for the response.
        StartCoroutine(WaitForRequest(www));
    }
示例#4
0
        //CRUD functions

        // C --> CRUD

        public int InsertCred(credentials cred)
        {
            //Adds the credentials into your DB
            var credItem = _context.Add(cred);

            //Save your changes
            _context.SaveChanges();

            //Returns the id of the newly added item back to you
            //View in postman
            return(credItem.Entity.id);
        }
示例#5
0
        public bool UpdateCredUserName(credentials credToUpdate)
        {
            return(_dataFromSql.UpdateAccountUsername(credToUpdate));
            // List<credentials> creds =new List<credentials>(_dataFromSql.GetCreds());
            // foreach(var item in creds){
            //     if(credToUpdate.id == item.id){

            //          ;
            //     }
            // }
            // return false;
        }
示例#6
0
        public bool CheckLogin(credentials credToAdd)
        {
            List <credentials> creds = new List <credentials>(_dataFromSql.GetCreds());

            foreach (var item in creds)
            {
                if (credToAdd.userName == item.userName && credToAdd.password == item.password)
                {
                    return(true);
                }
            }
            //Check if username in DB already(duplicate)
            return(false);
        }
示例#7
0
        public IActionResult Authenticate([FromBody] credentials usercredentials)
        {
            System.Console.WriteLine("*** Ravish says :: username  " + usercredentials.username + " :: password " + usercredentials.password);
            // var _user = _availableusers.Find(a => ((a.username == usercredentials.username) && (a.password == usercredentials.password)));
            var _user = _userService.Validate(usercredentials.username, usercredentials.password);

            if (_user == null)
            {
                return(BadRequest(new { message = "there is an issue with username or password" }));
            }
            else
            {
                return(Ok(_user));
            }
        }
        /// <summary>
        /// 1. Concatenate subjectType, identifier, uniqueReference, timestamp, algorithm and hmacKeyID into a single string, with a '!' inserted between each concatenated value.E.g. the result might be:
        ///CapitaPortal!37!X326736B!20110203201814!Original!2
        /// </summary>
        /// <param name="requestingCredentials"></param>
        /// <returns></returns>
        public static string GetCredentialsToHash(credentials requestingCredentials)
        {
            if (requestingCredentials != null)
            {
                string subjectType     = string.Empty;
                string identifier      = string.Empty;
                string uniqueReference = string.Empty;
                string timeStamp       = string.Empty;
                string algorithm       = string.Empty;
                string hmacKeyId       = string.Empty;

                if (requestingCredentials.subject != null)
                {
                    subjectType = requestingCredentials.subject.subjectType.ToString();
                }

                if (requestingCredentials.subject != null)
                {
                    identifier = requestingCredentials.subject.identifier.ToString();
                }

                if (requestingCredentials.requestIdentification != null)
                {
                    uniqueReference = requestingCredentials.requestIdentification.uniqueReference;
                }

                if (requestingCredentials.requestIdentification != null)
                {
                    timeStamp = requestingCredentials.requestIdentification.timeStamp;
                }

                if (requestingCredentials.signature != null)
                {
                    algorithm = requestingCredentials.signature.algorithm.ToString();
                }

                if (requestingCredentials.signature != null)
                {
                    hmacKeyId = requestingCredentials.signature.hmacKeyID.ToString();
                }

                return($"{subjectType}!{identifier}!{uniqueReference}!{timeStamp}!{algorithm}!{hmacKeyId}");
            }

            return(string.Empty);
        }
示例#9
0
 public bool UpdateAccountPassword(credentials cred)
 {
     try {
         var entry = _context.credential.First(e => e.id == cred.id);
         entry.password = cred.password;
         _context.Update <credentials>(entry);
         // _context.Entry (entry).CurrentValues.SetValues (cred);
         _context.SaveChanges();
         return(true);
     } catch (Exception e) {
         // handle correct exception
         // log error
         return(false);
     }
     // var credId = GetAccountById(cred.id);
     // _context.Update<credentials>(cred);
     // if you don't do a check for it being 0, then it would update all the fields
     // return _context.SaveChanges() !=0;
 }
示例#10
0
        public async Task <JsonResult> GenerateToken([FromBody] credentials item)
        {
            var disco = await DiscoveryClient.GetAsync("http://localhost:53721"); //8091

            if (disco.IsError)
            {
                Console.WriteLine(disco.Error);
            }

            // request token
            var tokenClient   = new TokenClient(disco.TokenEndpoint, "client", "secret");
            var tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync(item.username, item.password);

            if (tokenResponse.IsError)
            {
                Console.WriteLine(tokenResponse.Error);
            }

            return(Json(tokenResponse.Json));
        }
示例#11
0
        public IActionResult Login([FromBody] credentials user)
        {
            var verifiedUser = _context.credential.SingleOrDefault(u => u.userName == user.userName && u.password == user.password);

            if (verifiedUser != null)
            {
                var secretKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("superSecretKey@345"));
                var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);
                var tokeOptions       = new JwtSecurityToken(
                    issuer: "http://localhost:5000",
                    audience: "http://localhost:5000",
                    claims: new List <Claim>(),
                    expires: DateTime.Now.AddDays(5),
                    signingCredentials: signinCredentials
                    );
                var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions);
                return(Ok(new { Token = tokenString }));
            }
            return(null);
        }
 return(QueryProvider(identityProvider, proxySettings, credentials, authenticationType));
 => _httpClient = new CloudMessagingHttpClient(credentials, configuration);
示例#14
0
 public bool UpdateCredPassword(credentials credToUpdate)
 {
     return(_dataFromSql.UpdateAccountPassword(credToUpdate));
 }
示例#15
0
 public int AddCred(credentials credToAdd)
 {
     return(_dataFromSql.InsertCred(credToAdd));
 }