CodeIgniter Forums
[Solved] Getting SHA1 value from MySql - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [Solved] Getting SHA1 value from MySql (/showthread.php?tid=19569)



[Solved] Getting SHA1 value from MySql - El Forum - 06-11-2009

[eluser]VasilK[/eluser]
Hello!

I would like to know how I can use the SHA1 function from the MySQL. I am trying with this line:

Code:
$confirmation_hash = $this->db->query("SHA1('{$confirmation}')");

But I got this error: You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'SHA1

Could you please help me!

Thanks you!
Vasil


[Solved] Getting SHA1 value from MySql - El Forum - 06-11-2009

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums.

Try this:
Code:
$confirmation_hash = $this->db->query("SELECT SHA1('{$confirmation}')");

Not too sure why you're using the database for this, though...


[Solved] Getting SHA1 value from MySql - El Forum - 06-11-2009

[eluser]VasilK[/eluser]
Thank you for the warm welcome! Smile
[quote author="TheFuzzy0ne" date="1244745185"]
Try this:
Code:
$confirmation_hash = $this->db->query("SELECT SHA1('{$confirmation}')");
[/quote]

Yes, it's much better! Still, now I have problem to access the value. I tried with this:
Code:
$sample = $confirmation_hash->first_row('array');
But looks like the argument to access the filed in $sample is the value of the $confirmation itself... or maybe I did not understand it right! Could you please share with me the few lines how to get the value from this query. Thanks!

[quote author="TheFuzzy0ne" date="1244745185"]
Not too sure why you're using the database for this, though...[/quote]

Hm... I was being told that sometimes, the sha1 php function could be bit different from the MySQL SHA1. In this case, I use the MySQL SHA1 when saving in the database, so I need to create that one again.

Take care!
Vasil


[Solved] Getting SHA1 value from MySql - El Forum - 06-11-2009

[eluser]deanf7[/eluser]
if you're trying to retrieve the actual password you can't. It's a one way hash that can't be decrypted. If a user forgets their password you'd have to reset it.


[Solved] Getting SHA1 value from MySql - El Forum - 06-11-2009

[eluser]VasilK[/eluser]
[quote author="deanf7" date="1244749963"]if you're trying to retrieve the actual password you can't. It's a one way hash that can't be decrypted. If a user forgets their password you'd have to reset it.[/quote]

Yes, I know that!

What I am asking is: How I can get the SHA1 value from the result query?


[Solved] Getting SHA1 value from MySql - El Forum - 06-11-2009

[eluser]Evil Wizard[/eluser]
Something like this should help
Code:
$confirmation_hash = $this->db->query("SELECT SHA1('{$confirmation}') AS `confirmed`");
$sample = $confirmation_hash->row(0)->confirmed;



[Solved] Getting SHA1 value from MySql - El Forum - 06-11-2009

[eluser]VasilK[/eluser]
Done. Thank you all!

Looking forward of sharing with you here!
Vasil


[Solved] Getting SHA1 value from MySql - El Forum - 06-11-2009

[eluser]Evil Wizard[/eluser]
Although if it is just the sha1 value of $confirmation that you want, I would be more inclined to use the php sha1() function, got to be less overhead than a DB round trip