0
votes

I want to convert username and password fields that I'm using in my auth component to upper case, before the login action. I tried to set

text-transform:uppercase; 

in my CSS, for inputs, and it worked. But the uppercased information do not go to the database. The strings will only be uppercased if I write them with capslock. Could someone give me an example (for newbies)?

Thanks!

EDIT:

Here is my login action:

function login() {

if (!empty($this->data) && $this->Auth->user()) {
    $this->User->id = $this->Auth->user('id');
    $this->User->saveField('last_login', date('Y-m-d H:i:s'));
    $this->redirect($this->Auth->redirect());
}

}

1
that should work if its in the correct place. you'll have to provide more code. - sonjz
It works, visually... but the uppercased username and password, aren't what the database (firebird) is receiving, bexause the login don't work (all usernames and passwords in the data base are uppercased). But if I write the username and password with CAPSLOCK, everything works fine. - qxlab
also - uppercasing passwords is like a really bad idea and compromises the security of your users' passwords! i am sure some of them won't appropriate that. - mark
text-transform:uppercase will visibly change the change of the text but not the actual characters. They will be passed in original case but displayed as uppercase. - RichardAtHome

1 Answers

1
votes

you can uppercase in server-side php as demonstrated by @thecodeparadox, or you can do so with client-side javascript or if you're using jQuery, add it to your events.

html/javascript:

<form>
  <input type="text" name="username" onchange="this.value = this.value.toUpperCase();" />
  <input type="password" name="password" onchange="this.value = this.value.toUpperCase();" />
</form>​

demo: http://jsfiddle.net/85HEy/2/

or html/jQuery:

<form>
  <input type="text" name="username" />
  <input type="password" name="password" />
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script>
  $(document).ready(function() {
    $("input[name='username'], input[name='password']").change(function() {
      $(this).val($(this).val().toUpperCase());
    });
  });
</script>​

demo: http://jsfiddle.net/T9XbP/