';

MD5 string not displaying correctly with html ()

I have two spans with identifiers saltandpassword

<div>
    $salt = '<span id="salt"></span>';<br />
    $password = '<span id="password"></span>';
</div>

Then I use the following jQuery code, which accepts the salt, adds it to the password entered by the user, and returns both the salt and hashed password (for copying to the configuration file).

salt = (Math.random() +1).toString(36).substr(2, 16);
$('#salt').html(salt);
hashed = CryptoJS.MD5(salt + $(this).val());
$('#password').html(hashed);

This code adds salt to the range with the identifier salt, but it does not add anything to the identifier password.

If I enter the code alert(hashed), it will open a warning indicating the value of md5.

If I change .html()to .text(), it works.

+4
source share
1 answer

CryptoJS.MD5() . toString().

hashed = CryptoJS.MD5(value);
var hashedString = hashed.toString();

, jQuerys text(). jQuery html() innerHTML. .

$('#password').text(hashedString);

text(), toString(),

.text()

. Number Boolean , String. [...] , , HTML.

jQuery API : text()

.html(htmlString)

HTML

jQuery API : html()

+1

All Articles