ASP.NET MVC 5 Identity reset password

Eticaret2014.Models.AspNetUser user=db.AspNetUsers.FirstOrDefault(a=>userID==a.Id&&a.SifreSifirlama==sifirlamaSifresi);
            varuntil=DateTime.Now.AddDays(1);
            if(null!=user)
            {
                vartoken=newStringBuilder();
                //Prepare a 10-character random text
                using(RNGCryptoServiceProvider
                                    rngCsp=newRNGCryptoServiceProvider())
                {
                    vardata=newbyte[4];
                    for(inti=0;i<10;i++)
                    {
                        //filled with an array of random numbers
                        rngCsp.GetBytes(data);
                        //this is converted into a character from A to Z
                        varrandomchar=Convert.ToChar(
                            //produce a random number
                            //between 0 and 25
                                                  BitConverter.ToUInt32(data,0)%26
                            //Convert.ToInt32(‘A’)==65
                                                  +65
                                         );
                        token.Append(randomchar);
                    }
                }
                //This will be the password change identifier
                //that the user will be sent out
                vartokenid=token.ToString();
                //Generating a token
                varresult=await IdentityManager
                                        .Passwords
                                        .GenerateResetPasswordTokenAsync(
                                                      tokenid,
                                                      user.UserName,
                                                      until
                                   );
                if(result.Success)
                {
                           stringgizliParola=Membership.GeneratePassword(8,0);
                           gizliParola=Regex.Replace(gizliParola,@“[^a-zA-Z0-9]”,m=>“9”).ToLower();
                    varsonuc=await IdentityManager.Passwords.ResetPasswordAsync(tokenid,gizliParola);
                    if(sonuc.Success)
                    {
                        MailController.SifreGonder(user.UserName,“tr”,gizliParola);
                        TempData[“HataMesaj”]=“Şifre sıfırlama maili adresinize gönderildi. Lütfen mailinizi kontrol ediniz.”;
                    }
                    else
                    {
                        TempData[“HataMesaj”]=sonuc.Errors;
                    }
                }
            }
            returnView();

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Bu site, istenmeyenleri azaltmak için Akismet kullanıyor. Yorum verilerinizin nasıl işlendiği hakkında daha fazla bilgi edinin.