Post by fairmount » Mon May 21, 2012 6:20 am

Hi,

IN the forgotten password page, if teh entered email has a space before or after the email, it is returning 'email not found'.

How do we trim the empty spaces on either side before validating the email.

Code: Select all

if (!isset(trim($this->request->post['email'])))
doesn't seem to work. I also tried assigning it to a variable by doing

Code: Select all

$val = $this->request->post['email'];
if (!isset($val)) {
but even that doesn't seem to work.

Please help.
Regards,
FM

Newbie

Posts

Joined
Fri Apr 20, 2012 11:42 am

Post by Avvici » Mon May 21, 2012 1:12 pm

You really don't want to use trim for that. To get rid of white spaces in a string,
Try this:

Code: Select all

$trimmed_email = str_replace(" ", "", $this->request->post['email']);
In 1.5.2.1 Registration Validation:

Code: Select all

$trimmed_email = str_replace(" ", "", $this->request->post['email']);
if ((utf8_strlen($trimmed_email) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $trimmed_email)) {
      		$this->error['email'] = $this->language->get('error_email');
    	}
You could even trim all white spaces using a regular expression :D

Code: Select all

$mystring = preg_replace('/\s+/', '', $mystring);

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by greghl » Thu May 15, 2014 1:43 am

I found this thread because I'm also looking to trim white-space from email+ password for validation, the number of customers I am getting who say they cannot login is enormous. When I copy/paste their credentials, it works, so the only thing I can come up with, is sloppy copy+paste, ie, they have copied white-space before or after the email and/or password.

So - I was wondering why not use trim()?

The suggestion to use str_replace and the search term " " would only replace a space - what if thy copied a tab character, or a carriage return? Surely trim will clear up all offending characters:

the man page for trim() in php.net says:
http://php.net/manual/en/function.trim.php

" " (ASCII 32 (0x20)), an ordinary space.
"\t" (ASCII 9 (0x09)), a tab.
"\n" (ASCII 10 (0x0A)), a new line (line feed).
"\r" (ASCII 13 (0x0D)), a carriage return.
"\0" (ASCII 0 (0x00)), the NUL-byte.
"\x0B" (ASCII 11 (0x0B)), a vertical tab.

and why would this not be much more desirable than the method suggested by avvici-arvixe? Am I missing something here? (quite possible).

tia

Newbie

Posts

Joined
Thu May 15, 2014 1:39 am

Post by Avvici » Thu May 15, 2014 9:25 am

Trim works fine too. I was referring to one string...not a gazillion white spaces in a document

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by greghl » Thu May 15, 2014 9:07 pm

thx arvixe,

so I'm assuming to fix login issues with extra characters, that I need to be editing catalog/controller/module/account.php (I'm new to opencart + vqmod) - and doing that using vqmod I'm coming up with:

Code: Select all

                <file path="catalog/controller/module/account.php">
                        <operation info="Check customer Login">
                        <search position="after"><![CDATA[
                       $this->data['recurring'] = $this->url->link('account/recurring', '', 'SSL');
                        ]]></search>
                        <add><![CDATA[
                        //start======================login form=================================
                $this->language->load('account/login');

                $this->data['action'] = $this->url->link('account/login', '', 'SSL');
                $this->data['entry_email'] = $this->language->get('entry_email');
        $this->data['entry_password'] = $this->language->get('entry_password');
        $this->data['button_continue'] = $this->language->get('button_continue');
                $this->data['button_login'] = $this->language->get('button_login');

                if (isset($this->request->post['email'])) {
                        $this->data['email'] = trim($this->request->post['email']);
                } else {
                        $this->data['email'] = '';
                }

                if (isset($this->request->post['password'])) {
                        $this->data['password'] = trim($this->request->post['password']);
                } else {
                        $this->data['password'] = '';
                }

                $this->data['button_login'] = $this->language->get('button_login');

                if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
                        $this->data['redirect'] = $this->request->post['redirect'];
                } elseif (isset($this->session->data['redirect'])) {
                $this->data['redirect'] = $this->session->data['redirect'];

                        unset($this->session->data['redirect']);
        } else {
                        $this->data['redirect'] = '';
                }

//end======================login form=================================
                        ]]></add>
                </operation>
                </file>
can anyone else see what I'm missing, as this doesn't seem to work - if I copy/paste the password (known) - and add a space on the end, which I expect to get stripped... going to try this also:

Code: Select all

                <file path="catalog/controller/module/account.php">
                        <operation info="Check customer Login">
                        <search position="after"><![CDATA[
                       $this->data['recurring'] = $this->url->link('account/recurring', '', 'SSL');
                        ]]></search>
                        <add><![CDATA[
                        //start======================login form=================================
                $this->language->load('account/login');

                $this->data['action'] = $this->url->link('account/login', '', 'SSL');
                $this->data['entry_email'] = $this->language->get('entry_email');
        $this->data['entry_password'] = $this->language->get('entry_password');
        $this->data['button_continue'] = $this->language->get('button_continue');
                $this->data['button_login'] = $this->language->get('button_login');

                if (isset($this->request->post['email'])) {
                        $this->data['email'] = str_replace(' ', '', trim($this->request->post['email']));
                } else {
                        $this->data['email'] = '';
                }

                if (isset($this->request->post['password'])) {
                        $this->data['password'] = str_replace(' ', '', trim($this->request->post['password']));
                } else {
                        $this->data['password'] = '';
                }

                $this->data['button_login'] = $this->language->get('button_login');

                if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
                        $this->data['redirect'] = $this->request->post['redirect'];
                } elseif (isset($this->session->data['redirect'])) {
                $this->data['redirect'] = $this->session->data['redirect'];

                        unset($this->session->data['redirect']);
        } else {
                        $this->data['redirect'] = '';
                }

//end======================login form=================================
                        ]]></add>
                </operation>
                </file>
(I like the idea of the str_replace, but I always use single quotes on fixed strings - reserving double-quotes for instances where I have to include variables - ie, fixed strings= single quotes only.

Newbie

Posts

Joined
Thu May 15, 2014 1:39 am

Post by Avvici » Fri May 30, 2014 12:15 am

No problem

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC
Who is online

Users browsing this forum: No registered users and 74 guests