I’m not sure how this code relates to allowing the user to generate their own password. Surely all you need is a form input box for the password, and some code to hash it and store it in the database? Maybe you’d want some code to check for complexity and reject obvious passwords, but that could come later.