The generation of a random salt, when one was not provided, was in the wrong place and being generated too late to be used properly. Also, the generation of the value was duplicated.