It's amateur because it its terrible. You are causing so much overhead with the try catch... the system has to throw an exception and catch it, completely unneeded, just use a Regex, thats what it is there for.Is it amateur because it's just too simple?
You couldn't give this before right?Here is a more fullproof way to check the email. Regular Expressions are a big help
Code:public bool IsValidEmail(string email) { if(string.IsNullOrEmpty(email)) return false; const string regexString = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; return Regex.IsMatch(email, regexString); }
I think it shoud be "using System.Text.RegularExpressions;"I could have given it before, but if i don't let you try to figure it out, how will you learn? Also, i dont always have time to throw together a sample
Add
using System.Text; to the top of the file.
{
TextRelay relay = (TextRelay)info.GetTextEntry(2);
string txt1 = (string)relay.Text.Trim();
TextRelay relay2 = (TextRelay)info.GetTextEntry(3);
string txt2 = (string)relay2.Text.Trim();
if (ValidateEmail(txt1, txt2)) ///////214
{
string c = CreateConFirmation();
Account acct = (Account)from.Account;
string test = (string)acct.Username;
string email = txt1;
if (!EmailHolder.Confirm.ContainsKey(test))
{
EmailHolder.Confirm.Add(test, txt1);
EmailHolder.Codes.Add(test, c);
}
else
{
EmailHolder.Confirm.Remove(test);
EmailHolder.Codes.Remove(test);
EmailHolder.Confirm.Add(test, txt1);
EmailHolder.Codes.Add(test, c);
}
[/CODE][/FONT][/SIZE][/quote]Ah ya... so you are doing txt2.Text.Trim() but Text is null, so you need to add a check (and should probably add the same check for each of the TextRelay values.
Code:TextRelay txt2 = (TextRelay)info.GetTextEntry(3);[/FONT][/SIZE] [SIZE=13px][FONT=Consolas]string s2 = string.Empty;[/FONT][/SIZE] [SIZE=13px][FONT=Consolas]if(txt2.Text != null)[/FONT][/SIZE] [SIZE=13px][FONT=Consolas] s2 = txt2.Text.Trim();
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Gumps.ChangePasswordGump.OnResponse(NetState sender, RelayInfo info) in c:\Documents and Settings\Administrator\Desktop\Test Server\Scripts\XX Custom\PlayerCommands\Register Email\Gumps\ChangePasswordGump.cs:line 85
at Server.Network.PacketHandlers.DisplayGumpResponse(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)
case 1:
{
TextRelay txt = (TextRelay)info.GetTextEntry(2);
string s = (string)txt.Text.Trim();
TextRelay txt2 = (TextRelay)info.GetTextEntry(3);
string s2 = (string)txt2.Text.Trim();
if(txt2.Text != null)
s2 = txt2.Text.Trim();
TextRelay txt3 = (TextRelay)info.GetTextEntry(4);
string s3 = (string)txt3.Text.Trim();
if(txt3.Text != null)
s3 = txt3.Text.Trim();
if (ValidatePassword(from, s, s2, s3))
{
acct.SetPassword(s2);
from.SendMessage("Şifreniz değişti, yeni account detaylarınız emailinize yollandı.");
string msg = "Yeni şifreniz: \n\n" + s2 + "\n\n Account:\n\n" + acct.Username + "\n\n Bu email hacklenmeye karşı bir önlem olarak yollandı, Bu mesajın gönderiliş zamanı " + DateTime.Now.ToString() + " .\n \n Teşekkür Ederiz \n \n Game World Ultima Online Yönetim";
string email = (string)EmailHolder.Emails[acct.Username];
EmailEventArgs eea = new EmailEventArgs(true, null, email, "Şifreniz Değişti", msg);
RegisterEmailClient.SendMail(eea);
}
else
{
from.SendMessage("Ya girdiğiniz şifre eski şifrenizle uyuşmadı, ya da yeni şifrenizi ikinici sefer yanlış girdiniz, lütfen tekrar deneyin.");
}
break;
}
TextRelay txt = (TextRelay)info.GetTextEntry(2);
string s = (string)txt.Text.Trim();
TextRelay txt2 = (TextRelay)info.GetTextEntry(3);
string s2 = (string)txt2.Text.Trim();
if(txt2.Text != null)
s2 = txt2.Text.Trim();
TextRelay txt3 = (TextRelay)info.GetTextEntry(4);
string s3 = (string)txt3.Text.Trim();
if(txt3.Text != null)
s3 = txt3.Text.Trim();
TextRelay txt = (TextRelay)info.GetTextEntry(2);
string s = string.Empty;
if (txt.Text != null)
{
s = txt.Text.Trim();
}
TextRelay txt2 = (TextRelay)info.GetTextEntry(3);
string s2 = string.Empty;
if (txt2.Text != null)
{
s2 = txt2.Text.Trim();
}
TextRelay txt3 = (TextRelay)info.GetTextEntry(4);
string s3 = string.Empty;
if (txt3.Text != null)
{
s3 = txt3.Text.Trim();
}
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Gumps.ChangePasswordGump.OnResponse(NetState sender, RelayInfo info) in c:\Documents and Settings\Administrator\Desktop\Test Server\Scripts\XX Custom\PlayerCommands\Register Email\Gumps\ChangePasswordGump.cs:line 95
at Server.Network.PacketHandlers.DisplayGumpResponse(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)
TextRelay txt = (TextRelay)info.GetTextEntry(2);
string s = string.Empty;
if (txt.Text != null)
{
s = txt.Text.Trim();
}
TextRelay txt2 = (TextRelay)info.GetTextEntry(3);
string s2 = string.Empty;
if (txt2.Text != null) /////////// line 95
{
s2 = txt2.Text.Trim();
}
TextRelay txt3 = (TextRelay)info.GetTextEntry(4);
string s3 = string.Empty;
if (txt3.Text != null)
{
s3 = txt3.Text.Trim();
}
if (ValidatePassword(from, s, s2, s3))
{
acct.SetPassword(s2);
from.SendMessage("Şifreniz değişti, yeni account detaylarınız emailinize yollandı.");
string msg = "Yeni şifreniz: \n\n" + s2 + "\n\n Account:\n\n" + acct.Username + "\n\n Bu email hacklenmeye karşı bir önlem olarak yollandı, Bu mesajın gönderiliş zamanı " + DateTime.Now.ToString() + " .\n \n Teşekkür Ederiz \n \n Game World Ultima Online Yönetim";
string email = (string)EmailHolder.Emails[acct.Username];
EmailEventArgs eea = new EmailEventArgs(true, null, email, "Şifreniz Değişti", msg);
RegisterEmailClient.SendMail(eea);
}
else
{
from.SendMessage("Ya girdiğiniz şifre eski şifrenizle uyuşmadı, ya da yeni şifrenizi ikinici sefer yanlış girdiniz, lütfen tekrar deneyin.");
}
using System;
using Server;
using Server.Commands;
using Server.Items;
using Server.Mobiles;
using System.Collections;
using System.Collections.Generic;
using Server.Accounting;
using Server.Network;
using Server.Misc;
using Server.Multis;
using Server.Targeting;
using Server.Gumps;
using System.Net.Mail;
using System.Threading;
using System.Net;
namespace Server.Gumps
{
public class ChangePasswordGump : Gump
{
public ChangePasswordGump() : base(0, 0)
{
Closable = true;
Dragable = true;
Resizable = false;
AddBackground( 203, 176, 415, 171, 9300 );
AddBackground(209, 233, 402, 6, 9350);
AddLabel(350, 182, 0, "Change Password");
AddLabel(211, 208, 0, "Old PW:");
AddImage(332, 204, 1143);
AddTextEntry(340, 204, 257, 25, 0, 2, "");
AddLabel(215, 249, 0, "New PW:");
AddImage(333, 245, 1143);
AddTextEntry(341, 246, 257, 25, 0, 3, "");
AddLabel(218, 285, 0, "New PW:");
AddImage(333, 279, 1143);
AddTextEntry(341, 280, 256, 25, 0, 4, "");
AddButton(277, 316, 4005, 4006, 1, GumpButtonType.Reply, 0);
AddLabel(309, 317, 0, "OK");
}
public bool ValidatePassword(PlayerMobile m, string old, string new1, string new2)
{
Account acct = (Account)m.Account;
if (!acct.CheckPassword(old))
return false;
if (new1 == "" || new2 == "")
return false;
if (new1 != new2)
return false;
return true;
}
public override void OnResponse( NetState sender, RelayInfo info )
{
PlayerMobile from = (PlayerMobile)sender.Mobile;
Account acct = (Account)from.Account;
string key = (string)acct.Username;
switch (info.ButtonID)
{
case 0:
{
from.SendMessage("You choose to change you password.");
break;
}
case 1:
{
TextRelay txt = (TextRelay)info.GetTextEntry(2); string s = string.Empty; if (txt.Text != null) { s = txt.Text.Trim(); } TextRelay txt2 = (TextRelay)info.GetTextEntry(3); string s2 = string.Empty; if (txt2.Text != null) /////////// line 95 { s2 = txt2.Text.Trim(); } TextRelay txt3 = (TextRelay)info.GetTextEntry(4); string s3 = string.Empty; if (txt3.Text != null) { s3 = txt3.Text.Trim(); }
if (ValidatePassword(from, s, s2, s3))
{
acct.SetPassword(s2);
from.SendMessage("Your password has been changed.");
string msg = "Your new password: \n\n" + s2 + "\n\n Account:\n\n" + acct.Username + "\n\n This email send to prevent hacks. Time of the email: " + DateTime.Now.ToString() + " .\n \n Thank You \n \n ";
string email = (string)EmailHolder.Emails[acct.Username];
EmailEventArgs eea = new EmailEventArgs(true, null, email, "Your Password Changed", msg);
RegisterEmailClient.SendMail(eea);
}
else
{
from.SendMessage("Your old password wasn't true or your 2nd password was incorrect..");
}
break;
}
}
}
}
}