コード例 #1
0
        public async Task <AuthenticationResult> AuthenticateUserAsync(string username, string password, string address)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException(nameof(username));
            }

            if (string.IsNullOrWhiteSpace(address))
            {
                throw new ArgumentNullException(nameof(address));
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException(nameof(password));
            }

            ServerAddress = address;
            var bytes = Encoding.UTF8.GetBytes(password);
            var args  = new Dictionary <string, string>
            {
                ["username"]    = Uri.EscapeDataString(username),
                ["pw"]          = password,
                ["password"]    = BitConverter.ToString(CryptographyProvider.CreateSha1(bytes)).Replace("-", string.Empty),
                ["passwordMD5"] = GetConnectPasswordMd5(password)
            };

            var url    = GetApiUrl("Users/AuthenticateByName");
            var result = await PostAsync <AuthenticationResult>(url, args, CancellationToken.None);

            SetAuthenticationInfo(result.AccessToken, result.User.Id);

            return(result);
        }
コード例 #2
0
        public void CreateSha1Hash()
        {
            var password = Encoding.UTF8.GetBytes("password");
            var hash     = _cryptographyProvider.CreateSha1(password);

            hash.Should().NotBeNull("because sha1 needs to be generated");
            var stringHash = BitConverter.ToString(hash).Replace("-", string.Empty);

            stringHash.Should().Be("5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8");
        }