What is sha1()? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is sha1()?

Meaning of sha1() in php when connecting to database? Explain and give proper example pls

18th May 2019, 3:15 PM
Avijit Bakshi
Avijit Bakshi - avatar
6 Answers
+ 3
Thanks for the help...
19th May 2019, 1:21 PM
Avijit Bakshi
Avijit Bakshi - avatar
+ 2
sha1() is one of the hash function which is used to generate a hash value for given object. * Hash values are the unique string which can be used as the identifier for that object.
18th May 2019, 4:23 PM
Hardik Raut
Hardik Raut - avatar
+ 2
Still doesn't understand properly, give an example
18th May 2019, 4:55 PM
Avijit Bakshi
Avijit Bakshi - avatar
+ 2
you are welcome 💐
20th May 2019, 3:19 PM
Hardik Raut
Hardik Raut - avatar
+ 1
okay. following is a very simple example, * You have a file named sample.text which contains a huge text for eg say 10000 words. * You generated a hash of the file using any of the hashing method sha1,md5 or anything else & you got some string like this hsidgamdienwywjdk62neu19n1729ebw81bn * You sent the same file to someone else and he used same hashing function to generate the hash for the same file. he will also get hsidgamdienwywjdk62neu19n1729ebw81bn i.e the same hash. it's unique to the file you shared. but just in case if any of the letter/word is modified in the file the hash for the file will completely be different. even a minor change in a file completely changes the file hash. have you ever observed md5 or sha1 hash provided while downloading some software ? well if yes then the hash is provided to you to verify if the execution file you downloaded is original and not modified by any third party in between. and this is not enough about hashes they have plenty other usages.
18th May 2019, 5:17 PM
Hardik Raut
Hardik Raut - avatar
+ 1
The php thing you are talking about is not completely clear but I think following is something you may find useful. generally hashes are irreversible. ie. you can create hash of the file of the string but cat get back the original file or the string by it's hash value.. due to this hashes are used to store the passwords in the database.. eg if you entered the password helloWorld during signup , the hash of the "helloWorld" gets stored in the databse and not the keyword "helloWorld" this way if any hacker get access to your database they cant see the actual password .
18th May 2019, 5:22 PM
Hardik Raut
Hardik Raut - avatar