예제 #1
0
        public tbl_Audience SetPassword(tbl_Audience audience, string password)
        {
            //https://www.google.com/search?q=identity+securitystamp
            if (!_context.Set <tbl_Audience>()
                .Where(x => x.Id == audience.Id && x.SecurityStamp == audience.SecurityStamp)
                .Any())
            {
                throw new InvalidOperationException();
            }

            audience.ConcurrencyStamp = Guid.NewGuid().ToString();
            audience.SecurityStamp    = Guid.NewGuid().ToString();

            if (string.IsNullOrEmpty(password))
            {
                audience.PasswordHashPBKDF2 = null;
                audience.PasswordHashSHA256 = null;
            }
            else
            {
                audience.PasswordHashPBKDF2 = PBKDF2.Create(password);
                audience.PasswordHashSHA256 = SHA256.Create(password);
            }

            _context.Entry(audience).State = EntityState.Modified;

            return(_context.Entry(audience).Entity);
        }
예제 #2
0
        public tbl_User SetPassword(tbl_User user, string password)
        {
            //https://www.google.com/search?q=identity+securitystamp
            if (!_context.Set<tbl_User>()
                .Where(x => x.Id == user.Id && x.SecurityStamp == user.SecurityStamp)
                .Any())
                throw new InvalidOperationException();

            if (string.IsNullOrEmpty(password))
            {
                user.PasswordHashPBKDF2 = null;
                user.PasswordHashSHA256 = null;
            }
            else
            {
                user.PasswordHashPBKDF2 = PBKDF2.Create(password);
                user.PasswordHashSHA256 = SHA256.Create(password);
            }

            user.ConcurrencyStamp = Guid.NewGuid().ToString();
            user.SecurityStamp = Guid.NewGuid().ToString();

            _context.Entry(user).State = EntityState.Modified;

            return _context.Entry(user).Entity;
        }
예제 #3
0
        public uvw_User SetPassword(uvw_User user, string password)
        {
            //https://www.google.com/search?q=identity+securitystamp
            if (!_context.Set <uvw_User>()
                .Where(x => x.Id == user.Id && x.SecurityStamp == user.SecurityStamp)
                .Any())
            {
                throw new InvalidOperationException();
            }

            if (string.IsNullOrEmpty(password))
            {
                user.PasswordHashPBKDF2 = null;
                user.PasswordHashSHA256 = null;
            }
            else
            {
                user.PasswordHashPBKDF2 = PBKDF2.Create(password);
                user.PasswordHashSHA256 = SHA256.Create(password);
            }

            var rvalue = new SqlParameter("ReturnValue", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };

            var pvalues = new[]
            {
                new SqlParameter("Id", SqlDbType.UniqueIdentifier)
                {
                    Value = user.Id
                },
                new SqlParameter("PasswordHashPBKDF2", SqlDbType.NVarChar)
                {
                    Value = (object)user.PasswordHashPBKDF2 ?? DBNull.Value
                },
                new SqlParameter("PasswordHashSHA256", SqlDbType.NVarChar)
                {
                    Value = (object)user.PasswordHashSHA256 ?? DBNull.Value
                },
                rvalue
            };

            return(_context.SqlQuery <uvw_User>("EXEC @ReturnValue = [svc].[usp_UserPassword_Update] "
                                                + "@Id, @PasswordHashPBKDF2, @PasswordHashSHA256", pvalues).Single());
        }
예제 #4
0
        public override int Run(string[] remainingArguments)
        {
            try
            {
                if (_hashType == HashTypes.PBKDF2)
                {
                    Console.Write("Enter plain text value: ");
                    var clearText = StandardInput.GetHiddenInput();
                    var hashText  = PBKDF2.Create(clearText);

                    if (!PBKDF2.Validate(hashText, clearText))
                    {
                        Console.WriteLine("Failed to generate hash. Please try again.");
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("  Hash value: " + hashText);
                    }
                }

                if (_hashType == HashTypes.SHA256)
                {
                    Console.Write("Enter plain text value: ");
                    var clearText = StandardInput.GetHiddenInput();
                    var hashText  = SHA256.Create(clearText);

                    Console.WriteLine();
                    Console.WriteLine("  Hash value: " + hashText);
                }

                return(StandardOutput.FondFarewell());
            }
            catch (Exception ex)
            {
                return(StandardOutput.AngryFarewell(ex));
            }
        }