1

So I am trying to implement NT & Lan Manager hashes in JavaScript (yeah I know not the best language choice for it!) but its to be used on a simple static web page where post-backs are not possible - so no PHP or .NET or Java.

The Issue I'm having is the first part of the protocol, basically you must ensure that the password is 14 characters, if its over 14 you need to trim (easy), however if its under 14 you need to null pad the password string to get it to fourteen characters.

How does one null pad a string in JavaScript?

Please note, I'm not asking how to zero pad a string in Javascript.

(Also bonus question, if anyone knows of any pre-made NT or LM hashing libraries in JS, I'd really appreciate the heads up!)

1 Answer 1

6
function nullpad( str, len ) {
    if( str.length >= len ) {
        return str;
    }

    return str + Array( len-str.length + 1 ).join("\x00");
}

nullpad( "", 15 ).length
//15

nullpad( "asd", 15 ).length
//15
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.