4 Replies - 6618 Views - Last Post: 02 September 2012 - 10:56 AM

#1 Jiro_  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 62
  • Joined: 27-August 12

comparisation of equal numbers fails

Posted 02 September 2012 - 05:58 AM

I am making a log in that stores the values in the registry. for security reasons the values are hashed using the .GetHashCode() function. the code I am using looks like this:
private: System::Void btnLogin_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				 //check the registry for existance of the key
				 if (check_key() == false) //unable to read the registry
				 {
					 MessageBox::Show("unable to read keys\nrestart application as administrator","error reading keys!",MessageBoxButtons::OK,MessageBoxIcon::Error);
					 return;
				 }
				 Microsoft::Win32::RegistryKey ^key = Microsoft::Win32::Registry::LocalMachine->OpenSubKey("SOFTWARE\\Gshell",true);
				 int ^username = int::Parse(key->GetValue("username")->ToString()),^password = int::Parse(key->GetValue("password")->ToString());
				 int ^userEntry = txtUsername->Text->GetHashCode(), ^passEntry = txtPassword->Text->GetHashCode();
				 Console::WriteLine("value from registry: " + username + " value from user entry: " + txtUsername->Text->GetHashCode());
				 if (username == userEntry && password == passEntry)
				 {
					 //we have a winner :P/>
					 MessageBox::Show("login successfull!","success",MessageBoxButtons::OK,MessageBoxIcon::Information);
				 }
				 else
				 {
					 MessageBox::Show("invalid credentials","error logging in",MessageBoxButtons::OK,MessageBoxIcon::Error);
				 }
			 }
private: System::Void lnkRegister_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e)
		 {
			 challenge::frmRegister ^reg = gcnew challenge::frmRegister();
			 reg->ShowDialog();
		 }
private: System::Void btnCancel_Click(System::Object^  sender, System::EventArgs^  e)
		 {
			 System::Windows::Forms::Application::Exit();
		 }
protected: System::Boolean check_key()
		   {
			   try
			   {
				   Microsoft::Win32::RegistryKey ^key;
				   key = Microsoft::Win32::Registry::LocalMachine->OpenSubKey("SOFTWARE\\Gshell",true);
				   System::String ^obj = key->GetValue("username")->ToString();
				   //success reading registry
				   return true;
			   }
			   catch (...)
			   {
				   //unable to read registry
				   return false;
			   }
		   }
};


now when the values are printed, they appear equal. though when I use a breakpoint and look at the locals in Visual Studio, the values (in hex) are different... does anyone knows how to solve this?

Is This A Good Question/Topic? 0
  • +

Replies To: comparisation of equal numbers fails

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5464
  • View blog
  • Posts: 11,731
  • Joined: 02-June 10

Re: comparisation of equal numbers fails

Posted 02 September 2012 - 06:17 AM

You're going through all this for security... but hash codes aren't at all secure.

Why not use one of the numerous cryptography schemes available?
Was This Post Helpful? 1
  • +
  • -

#3 Jiro_  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 62
  • Joined: 27-August 12

Re: comparisation of equal numbers fails

Posted 02 September 2012 - 07:49 AM

View PosttlhIn`toq, on 02 September 2012 - 06:17 AM, said:

You're going through all this for security... but hash codes aren't at all secure.

Why not use one of the numerous cryptography schemes available?

because honestly my C++ skills are not good enough to start with cryptography :| I'll try to work with those though. thank you very much
Was This Post Helpful? 0
  • +
  • -

#4 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2533
  • View blog
  • Posts: 4,633
  • Joined: 24-September 10

Re: comparisation of equal numbers fails

Posted 02 September 2012 - 08:38 AM

note, tlhIn'toq linked you a google search that supplies various libraries that do it for you!

Are you saying your C++ skills are not good enough to incorporate a 3rd party library? If so, then get those damn skills!
Was This Post Helpful? 0
  • +
  • -

#5 Jiro_  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 62
  • Joined: 27-August 12

Re: comparisation of equal numbers fails

Posted 02 September 2012 - 10:56 AM

I noticed his links :) and I'm studying them at the moment. I just said that I didn't considered myself well enough to be using cryptography, that's all
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1