Extract out generating secret into function.

refs #14919
Update doc strings and comments.

refs #14919