So i was unable to get the one in fsod working, so i made a new one.
ForgotPassword.cs
Code:
#region
using db;
using System;
using System.Collections.Specialized;
using System(DOT)IO;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;
#endregion
namespace server.account
{
internal class forgotPassword : RequestHandler
{
protected override void HandleRequest()
{
using (Database db = new Database())
{
//Generates a random password
string password = Database.GenerateRandomString(10);
//Changes the users password
var cmd = db.CreateQuery();
cmd.CommandText = "UPDATE accounts SET password=SHA1(@password) WHERE uuid=@email;";
cmd.Parameters.AddWithValue("@password", password);
cmd.Parameters.AddWithValue("@email", Query["guid"]);
if (cmd.ExecuteNonQuery() == 1)
{
//Makes the email sending function
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("YOURSERVEREMAIL", "YOURSERVERPASSWORD"); //Email credentials
//Email information
MailMessage mm = new MailMessage("RANDOMEMAILHERE", Query["guid"], "SERVERNAME", "SERVERNAME");
mm.Body = "Your new password for SERVERNAME is: " + password + " hopefully you wont forget your password again.";
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
//Send the actual email
client.Send(mm);
//Logs the action
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Reset Password Link sent to " + Query["guid"]);
Console.ForegroundColor = ConsoleColor.White;
}
else
using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
wtr.Write("<Error>Error.accountNotFound</Error>");
}
}
}
}
I put some words with caps, that you'd have to change to make it work.
If you are using this, and removed encryption from passwords, you need to remove the SHA1 from this code.
Also make sure the email you are using, doesnt have any security because if it does, the email wont send.
Replace (DOT) with "."