private static string GetRandomFilename(string folder = "")
        {
            if (!folder.IsNullOrEmpty() && !folder.EndsWith("/"))
            {
                folder = folder + '/';
            }

            return($"{folder}{SessionExtensions.CreateRandomBase62Id(24)}.png");
        }
Esempio n. 2
0
        public object Any(ForgotPassword request)
        {
            var res  = new ForgotPasswordResponse();
            var user = UserAuthRepository.GetUserAuthByUserName(request.Email);

            if (null == user)
            {
                res.Success = false;
                res.Message = "Invalid email address.";
                return(res);
            }

            var secret = Regex.Replace(SessionExtensions.CreateRandomBase62Id(32), @"[^\w\d]", "",
                                       RegexOptions.IgnoreCase);
            var link    = $"{Configuration.Web.Domain}{Configuration.Web.PasswordResetLinkFormat.Fmt(user.Email, secret)}";
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress(Configuration.Mail.From));
            message.To.Add(new MailboxAddress(user.Email));
            message.Subject = "[Derprecated] Password Reset";
            message.Body    = new TextPart("html")
            {
                Text =
                    $@"
                <html>
                    <head></head>
                    <body>
                        <p>
                            Click on the following link to reset your password:
                            <br/><br/>
                            <a href=""{
                        link}"">{link
                        }</a>
                            <br/><br/>
                            This link will expire in 4 hours.
                        </p>
                    </body>
                </html>
                "
            };

            Cache.Set($"password:secret:{user.Email}", secret, Expiration);
            SmtpClient.Send(message);

            res.Success = true;
            res.Message = null;

            return(res);
        }
        public void Does_CreateRandomBase62Id_16_byte_id_in_less_than_3_attempts_avg()
        {
            Assert.That(SessionExtensions.CreateRandomBase62Id(16).Length, Is.EqualTo(24));

            int attempts = 0;

            1000.Times(i =>
            {
                do
                {
                    attempts++;
                } while (SessionExtensions.CreateRandomBase64Id(16).IndexOfAny(new[] { '+', '/' }) >= 0);
            });

            attempts.Print();
            Assert.That(attempts, Is.LessThan(1000 * 3));
        }
Esempio n. 4
0
 public virtual string CreateApiKey(string environment, string keyType, int sizeBytes)
 {
     return(SessionExtensions.CreateRandomBase62Id(sizeBytes));
 }