cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

How to install JS extension

AlexK
14-Alexandrite

How to install JS extension

Hello Community

 

I am trying to set up a password verification in Java Script and I need to use a external library for the hashing. How can I define the CryptoJS.md5 function that is used in the code below?

//====================================================================
//functon for loading of javascript and css
//====================================================================
$scope.loadjscssfile= function(filename, filetype){
  console.log("loading "+filename+":: type="+filetype)
    if (filetype=="js"){ //if filename is a external JavaScript file
        var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype=="css"){ //if filename is an external CSS file
        var fileref=document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

//====================================================================
// Enter the View
//====================================================================
$scope.$on('$ionicView.afterEnter', function()  {
 
 /*$scope.loadjscssfile("app/resources/Uploaded/picker/lib/simplepicker.css", "css")*/
  $scope.loadjscssfile("app/resources/Uploaded/md5.js", "js");
  
})
function generatePasswordHash(password) {
  var hash = CryptoJS.MD5(password).toString();
  console.log(hash);
  // Use the generated hash as needed
}

var password = 'myPassword123';
generatePasswordHash(password);

Thanks for your help.

 

Best whishes

 

Alex

1 ACCEPTED SOLUTION

Accepted Solutions

This a little complex loading lots of files plus that archive is old.

 

Maybe you could use https://cdnjs.com/libraries/crypto-js

 

get the js downloaded as one file and then 

 


const cryptoscript = document.createElement('script');

cryptoscript.src="app/resources/Uploaded/cryto-min.js";
document.head.appendChild(cryptoscript);
var password = 'myPassword123';

cryptoscript.onload = function() {

generatePasswordHash(password);

}

function generatePasswordHash(password) {

var hash = CryptoJS.MD5(password).toString();
console.log(hash);
// Use the generated hash as needed
}

 

View solution in original post

4 REPLIES 4

This a little complex loading lots of files plus that archive is old.

 

Maybe you could use https://cdnjs.com/libraries/crypto-js

 

get the js downloaded as one file and then 

 


const cryptoscript = document.createElement('script');

cryptoscript.src="app/resources/Uploaded/cryto-min.js";
document.head.appendChild(cryptoscript);
var password = 'myPassword123';

cryptoscript.onload = function() {

generatePasswordHash(password);

}

function generatePasswordHash(password) {

var hash = CryptoJS.MD5(password).toString();
console.log(hash);
// Use the generated hash as needed
}

 

AlexK
14-Alexandrite
(To:sgreywilson)

Hi Steve

 

Thanks for your reply. 

 

I am still getting this error: "Uncaught ReferenceError: CryptoJS is not defined"

 

Do I need to make changes to the js file so the CryptoJS is defined?

 

I've uploaded the Project file.

 

Best wishes

 

Alex

aletenti2
6-Contributor
(To:AlexK)

Hi Alex,

I have imported your "Login_Test_Project" and I noticed that the md5.js file is totally empty. This is the issue.

Try to fill the file with the text contained in this link: https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js

and retry. It should work

AlexK
14-Alexandrite
(To:aletenti2)

Thanks, it worked!

Top Tags