-1

I have to generate a secure token.This token will be consumed by WebApi. I'm requesting that Webapi through JavaScript file. It is a SPA app. So my question is, can I generate below mentioned token without using the Sql server response ?

The SQL syntax in Microsoft SQL Server to generate such a token is:

SELECT HASHBYTES('MD5', convert(varchar,getdate(),112) + Mysc@re4+)
Sampath
  • 63,341
  • 64
  • 307
  • 441
  • Do you want to generate the hash in JavaScript rather than using the SQL Server function? If so, check out [the functions in this question/answer](http://stackoverflow.com/questions/14733374/how-to-generate-md5-file-hash-on-javascript) – Scottie Aug 18 '16 at 13:03
  • @Scottie Yes,exactly what I need.But one question though,will it generate the same hash as Sql one above ? – Sampath Aug 18 '16 at 13:15
  • yes, it will generate the same hash so long as you choose the same hashing algorithm - e.g. MD5 – Scottie Aug 18 '16 at 13:36
  • Thanks a lot @Scottie Can you put your comments as an answer ? Then I can close this post :) – Sampath Aug 18 '16 at 13:42

1 Answers1

-1

OP's Feedback :

I have used angular-md5 module.Here how to use it.

<body ng-app="YOUR_APP" ng-controller="MainCtrl">
  <img src="http://www.gravatar.com/avatar/{{ email | gravatar }}">
  <input type="email" ng-model="email" placeholder="Email Address">
  {{ message }}
</body>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js"></script>
<script src="app/bower_components/angular-md5/angular-md5.js"></script>
<script>
  angular.module('YOUR_APP', [
    'angular-md5', // you may also use 'ngMd5' or 'gdi2290.md5' 
    'controllers'
  ]);
  angular.module('controllers', [])
    .controller('MainCtrl', ['$scope', 'md5', function($scope, md5) {

      $scope.$watch('email' ,function() {
        $scope.message = 'Your email Hash is: ' + md5.createHash($scope.email || '');
      });

    }]);
</script> 

Another way :

You can generate an MD5 hash in JavaScript using the Crypto-JS library:

<html>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/core.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/md5.js"></script>
  <body>
    <script>
      var test = CryptoJS.MD5("string to hash");
      alert(test);
    </script>
  </body>
</html>
Sampath
  • 63,341
  • 64
  • 307
  • 441
Scottie
  • 545
  • 4
  • 14