Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Net.Mail;
- using MySql.Data.MySqlClient;
- using System.Web.UI;
- using System.IO;
- public class RestorePswd
- {
- public static void CanRestore(string username, string email, Page page)
- {
- if (username == "" || email == "")
- {
- SweetAlertCustom.SendCustomAlert(page, "Please fill all the boxes.", "ALERT!", "OK", SweetAlertCustom.types.error);
- return;
- }
- if (username.Length > 15 || email.Length > 40)
- {
- SweetAlertCustom.SendCustomAlert(page, "Wrong input.", "ALERT!", "OK", SweetAlertCustom.types.error);
- return;
- }
- string path = Constants.GlobalAccountsPath + username + ".txt";
- if (File.Exists(path))
- {
- string Data = File.ReadAllText(path);
- if (Data == email)
- {
- using (SmtpClient client = new SmtpClient())
- {
- client.Host = "smtp.gmail.com";
- client.Port = 587;
- client.EnableSsl = true;
- client.DeliveryMethod = SmtpDeliveryMethod.Network;
- client.Credentials = new System.Net.NetworkCredential("dukepaypal97@gmail.com", "bbmmtmi99Z");
- client.Timeout = 600000;
- using (MailMessage mm = new MailMessage("dukepaypal97@gmail.com", email, "Password Recovery", GetRecoveryContent(username)))
- client.Send(mm);
- }
- SweetAlertCustom.SendCustomAlert(page, "Your new password has been sent on your email.", "SUCCESS!", "OK", SweetAlertCustom.types.success);
- }
- }
- }
- public static bool ValidToken(string token, string username)
- {
- string path = Constants.PasswordRecoverPath + username + ".txt";
- if (!File.Exists(path))
- return false;
- string[] data = File.ReadAllLines(path);
- if (data[0] != token)
- return false;
- if (DateTime.FromBinary(long.Parse(data[1])) > DateTime.Now.AddHours(24))
- {
- File.Delete(path);
- return false;
- }
- return true;
- }
- static char[] Alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz".ToArray();
- static Random rnd = new Random();
- public static string RandomToken()
- {
- string ps = "";
- for (int i = 0; i < 50; i++)
- ps += Alphabets[rnd.Next(0, Alphabets.Length)];
- return ps;
- }
- public static string GetRecoveryContent(string username)
- {
- string path = Constants.PasswordRecoverPath + username + ".txt";
- string Token = RandomToken();
- if (File.Exists(path))
- File.Delete(path);
- string[] textlines = new string[2];
- textlines[0] = Token;
- textlines[1] = DateTime.Now.ToBinary().ToString();
- File.WriteAllLines(path, textlines);
- string link = "http://164.132.192.3/reset?token=" + Token + "&user=" + username;
- string content = "Hello " + username + ",\n\nYou have requested a password recovery link!\n\nPlease follow this link and enter your new password.\n\n" + link + "\nThis link will expire after 24 hours from now!\n\nThanks,\nPureClassic Team.";
- return content;
- }
- public static void DirectChange(string username, string newpass, Page page)
- {
- if (username == "" || newpass == "") page.Response.Redirect("Home");
- string path = Constants.GlobalAccountsPath + username + ".usr";
- if (File.Exists(path))
- File.Delete(path);
- MemoryStream ms = new MemoryStream();
- BinaryWriter BW = new BinaryWriter(ms);
- BW.Write(newpass);
- BW.Write("");
- byte[] buffer = ms.ToArray();
- BW.Close();
- ms.Close();
- File.WriteAllBytes(Constants.GlobalAccountsPath + username + ".usr", buffer);
- File.Delete(Constants.PasswordRecoverPath + username + ".txt");
- SweetAlertCustom.SendCustomAlert(page, "Your password has changed successfully!.", "Success", "COOL", SweetAlertCustom.types.success);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement