Skip to main content
15-Moonstone
June 26, 2023
Solved

How to install JS extension

  • June 26, 2023
  • 1 reply
  • 2525 views

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

Best answer by sgreywilson

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
}

 

1 reply

16-Pearl
June 26, 2023

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
}

 

AlexK15-MoonstoneAuthor
15-Moonstone
June 27, 2023

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

12-Amethyst
June 30, 2023

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