コード例 #1
0
        public async Task SendOneTimePassword(User user)
        {
            string otp = RSG.Generate(8);

            dbContext.OneTimePasswordForLogin.Add(new OneTimePasswordForLogin
            {
                Id        = Guid.NewGuid(),
                User      = user,
                Password  = otp,
                CreatedOn = DateTime.UtcNow,
            });
            dbContext.SaveChanges();

            var email = new MailBuilder(this.mailConfig)
                        .AddRecipients(user.Username)
                        .WithSubject("New Requestr login")
                        .WithBody($"Your login code is: {otp}")
                        .Build();

            if (!await this.emailService.SendMail(email))
            {
                throw new Exception("One time password could not be sent.");
            }
        }
コード例 #2
0
        private (string password, string salt) Hash(string password)
        {
            string salt = RSG.Generate(16);

            return(Hash(password, salt), salt);
        }