Hash password - help to understand


#1

Hi all,

We received this code from our professor to use in our project. However, we don’t quite understand the for loop and all the numbers that are equal to a, o, and c. Can anyone please clarify what this do for our code in detail? We know the overall function of the code though :slight_smile:

// We use a function to hash our passwords in order to make sure they are not stored in clear text

function hashPassword(rawPassword){
var a = 1, c = 0, h, o;
if (rawPassword) {
a = 0;

//This is a loop that goes through all passwords and emails

for (h = rawPassword.length - 1; h >= 0; h--) {
  o = rawPassword.charCodeAt(h);
  a = (a<<6&268435455) + o + (o<<14);
  c = a & 266338304;
  a = c!==0?a^c>>21:a;
}

}

return String(a);
}