Saturday, December 1, 2012

MySQL PASSWORD() function in JavaScript


If you need to implement a MySQL PASSWORD() function in JavaScript - use http://code.google.com/p/crypto-js/#SHA-1 with 2 encodings.

Here is an example:

var password = "TestPassword";
var result = ("*"+CryptoJS.SHA1(CryptoJS.SHA1(password))).toUpperCase();
console.log("result : " + result);

Result will be *0F437A73F4E4014091B7360F60CF81271FB73180. If you check it with MySQL password() it will be the same:

mysql> select password("TestPassword") as result;
+-------------------------------------------+
| result                                    |
+-------------------------------------------+
| *0F437A73F4E4014091B7360F60CF81271FB73180 |
+-------------------------------------------+

14 comments:

  1. You have provided a nice article, Thank you very much for this one. And I hope this will be useful for many people. And I am waiting for your next post keep on updating these kinds of knowledgeable things
    Java Training in Chennai
    Java Training in Coimbatore
    Java Training in Bangalore

    ReplyDelete
  2. Nice content very helpful, It has a very important point which should be noted down. All points mentioned and very well written. Keep Posting & writing such content

    AWS Online Training

    ReplyDelete
  3. I'm for the essential time frame here. I found this board and I in finding It in reality obliging and it helped me out abundance. I'm needing to expertise something already and sponsorship happening others, for instance, you helped me.
    Activate Office 2016 Crack

    ReplyDelete
  4. Photographs taken from the top floor using a Supreme IDimager Photo display precisely suited images because of primary.
    https://thepcsoft.com/idimager-photo-supreme-crack/

    ReplyDelete