Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6248665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:06:03+00:00 2026-05-24T13:06:03+00:00

If you use a database to store users you could save user info as

  • 0

If you use a database to store users you could save user info as shown below:
(from the Symfony security book.)

$factory = $this->get('security.encoder_factory');
$user = new Acme\UserBundle\Entity\User();

$encoder = $factory->getEncoder($user);
$password = $encoder->encodePassword('mypassword', $user->getSalt());
$user->setPassword($password);

However, I want to create reusable a User form:

namespace App\Bundle\WebBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class UserType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('username')
            ->add('password')
        ;
    }

    public function getName()
    {
        return 'app_bundle_webbundle_usertype';
    }
}

And use the form in a controller:
(from here)

if ($request->getMethod() == 'POST') {
    $form->bindRequest($request);

    if ($form->isValid()) {
        $em = $this->getDoctrine()->getEntityManager();
        $em->persist($task);
        $em->flush();

        return $this->redirect($this->generateUrl('task_success'));
    }
}

Where should you put the code used to hash your password shown at the beginning of this post (and the code to generate the salt, for that matter) in order to make it reusable and compatible with the $form->bindRequest() approach, in case you need for both a user registration form and a user profile edit form, etc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:06:04+00:00Added an answer on May 24, 2026 at 1:06 pm

    I recommend looking into: https://github.com/FriendsOfSymfony/FOSUserBundle . Even if you want to write your own solution, you can get very good ideas from that bundle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use a database and PHP sessions to store a user's shopping
My application makes use of a SQLite database to store the user's inputs. The
I'd like to use a database to store i18n key/value pairs so we can
I Use a Sql Server Compact Edition Database File For Store the Data in
Should I use decimal or float to store a ratio in a database? Particularly
What methods to use a database from Clojure are there? I know from Clojure
I am working on a feature and could use opinions on which database I
Many databases I've encountered (Like SQL Server) use a single file to store the
I currently work with an Oracle database and we use stored procedures for all
MySQL uses the USE database_name to change the active database. Does that work on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.