Password field required compatibility?

Recommended Posts

Is the password field compatible with the "required" option?

I only ask because if I make it a required option when editing a page if I haven't changed the password, it throws a required error. Obviously I'd like for the user to be able to leave it blank and leave the password how it is.

The problem is if I don't make it required then I may end up without a password at all.

Is this something I should look to triggering via a module?


Share this post

Link to post
Share on other sites

Hi onjegolders,

Are you working with the admin backend? I gave your case a try with the API:

$page->requiredField = "";

Nothing happened. Literally nothing: no errors, no field update.

Share this post

Link to post
Share on other sites

Thanks Valery, yes this is in the backend. On page save, the required error still gets called even if previously a password has been set. This must be because the password field is empty and it's only if a user fills it in that it gets reset.

Share this post

Link to post
Share on other sites

I took a peek at the system password field settings just out of curiosity.

It is not required.

And it's actually possible to create a user without a password. But they won't be able to log in: PW would silently redirect them back to the login page.

Share this post

Link to post
Share on other sites

Thanks Valery. 

I think I should specify, I'm adding the password field to a different page and adding the required value myself in the file settings.

Essentially it's so that my client can create a "member" while also creating a user without having to also remember to go to Access->Users and add one there.

Ideally the password field would be required initially when they add the page but perhaps thereafter not required. Either that or the value of a password field on the edit page template should not be empty.

Share this post

Link to post
Share on other sites

If all of this happens in the backend and the field is "required", the PW backend will not allow to blank it. You would have to write your own template for it to work. You won't even need the "required" option then.

Sorry if that's a poor solution. Maybe someone else can come up with a bright idea?

  • Like 1

Share this post

Link to post
Share on other sites

Thanks anyway Valery, it's useful having different thoughts on it!

I just imagined that as it's part of the core there must be some expected behaviour in this scenario.

Share this post

Link to post
Share on other sites

The only time you'd want to make the password field required is when using it for a new user form or something like that. Otherwise, I'd suggest not making it a required field unless you want people to change their password every time. I'm not positive about what your context is in this case, but because the built-in password field is designed for a very specific purpose, you might just want to use your own markup for a password field. Or, if using an InputfieldForm, you can use InputfieldText and change the type attribute to 'password':

$pass = $modules->get('InputfieldText'); 
$pass->attr('type', 'password'); 
$pass->attr('name', 'pass'); 
$pass->label = 'Your password';
$pass->required = (bool) whateverConditionYouWant(); 

Share this post

Link to post
Share on other sites

Thanks Ryan,

The context would be, like you said, a first time adding of a password for a user. Except a page (student) is being mapped to a user. So if the admin wants to update a student's password, they could also do it from the student page.

Obviously making it required will be unhelpful because it's only required once, unless the password field had some way of knowing that it hadn't been overriden this time but that it was set and not "blank".

I think failing that, the best way is for me to make it not required and the admin will have to remember if someone can't login, it's probably because they failed to assign them a password.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Sten
      I have a lot of difficulties with getting a field value.
      First I created a template, inside I created several fields
      two fields are a dropdown select box So I have a value and a label for each line.
      Then I want to get the field value in _init.php or in the template to display it. How can I get the value of a field for the page ? I need to understand the flow through which data goes.
      Could someone help me ?
      Thank you
    • By chcs
      After running this code in my module's __install() the template_id is not set. Any ideas why?  (The export contents from the template created and the one that I built with Admin are the same. Both exports have the template_id is set to mm_state. When I go to edit the field in Admin, the template is not showing on the Input tab and it doesn't show the template title on a page using the template that uses this field. Using processwire 3.0.98)

      // mm_state
      $field = $this->fields->get('mm_state');
      if (!@$field->id) $field = new Field();
      $field->type = $this->modules->get("FieldtypePage");
      $field->name = 'mm_state';
      $field->label = 'State';
      $field->derefAsPage = 2;
      $field->inputfield = "InputfieldSelect";
      $field->labelFieldName = 'title';
      $field->template_id = 'mm_state';
      $field->columnWidth = 100;
      $field->required = true;
    • By anttila
      We are developing an App that sends data over the Internet to ProcessWire (POST/JSON). We want password to be protected somehow when sending it, but I should be able to compare it to PW's passwords. We were thinking of using md5 encryption, but PW uses different encryption.
      How can I be sure that user has active account when they use the App?
    • By rareyush
      I added a field type 'page reference' using checkboxes knows as services.
      now i want to display the pages according to service.
      I can display all services list but when i click on any services then I can see whole code of site 
      any idea where i am wrong
      main cate1 subcate1 subcate2 cate2 subcate1 subcate2 services first-service second services  
      these services is being used as a page reference  in subcate1, subcate2 templates.
      and in the navbar when i click on services and then when i click on any of the following service then i can see whole source code of my site.
    • By benbyf
      Hello, having trouble getting PW to save my user or field in cron hook.
      It seems to report the same field info each time unchanged. It should be counting down in seconds.
      public function init() { // set to every30Seconds in settings $this->defaultInterval = $this->cron_check; // add hooks to CRON $this->addHookAfter("LazyCron::{$this->defaultInterval}", $this, 'checkUserSubscription'); } public function ___checkUserSubscription(HookEvent $e){ // seconds since last lazycron $seconds = $e->arguments[0]; $log = wire('log'); $field = $this->exclusiveRole; // users with specific role and field $users = $this->users->find("roles=$field"); foreach ($users as $user) { // get stored time $currentTime = $user->get($this->fieldName); // if time not null if($currentTime){ // evalute stored time minus time past $resultTime = intval($currentTime) - intval($seconds); $log->message("result ".$resultTime); // save user page $user->set($this->fieldName, $resultTime); $this->users->save($user); } } }