Welcome Guest, Not a member yet? Register   Sign In
[Solved] Getting SHA1 value from MySql
#1

[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
#2

[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...
#3

[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
#4

[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.
#5

[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?
#6

[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;
#7

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

Looking forward of sharing with you here!
Vasil
#8

[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




Theme © iAndrew 2016 - Forum software by © MyBB