0

In my sample login form, I am trying to connect to json and get the result ie., true, if username and password matches, else false.

json (exists in my project folder)

{
 "form": {
    "login": [
    {
      "username": "venkat",
      "password": "123"
    },
    {
      "username": "admin",
      "password": "345"
    }
  ]
}

I created a function like below. But I don't know what to do next. The sencha documentation has methods like ajax, proxy for MVC architecture, which I am not using.

function checkJson(username, password){
    //What should I write here?
    //Return true, if match
    //else false
}
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
  • Where does this json exit? – Izhaki Feb 12 '13 at 12:34
  • @Izhaki In my project folder.. – Mr_Green Feb 12 '13 at 12:35
  • You can't do anything with a static JSON file because it's static. You need to process it (PHP, Java, .NET, other) to take the information and get a result. – Evan Trimboli Feb 12 '13 at 12:36
  • @EvanTrimboli Can we use REST to do that? (I am not familiar with it, just asking) – Mr_Green Feb 12 '13 at 12:38
  • 1
    Well, you can get it with a simple ajax call. But do you seriously plan to return user passwords to the client side - every user will be able to see these with a click of a button. You should really send the password/user name to the server to do the checks. – Izhaki Feb 12 '13 at 12:44
  • @Izhaki Sorry for asking noob question, instead of checking at server, can we do the same using REST? – Mr_Green Feb 12 '13 at 12:47
  • Please have a look at [this SO answer](http://stackoverflow.com/questions/14810340/load-new-view-after-the-loginin-extjs-4-mvc/14812218#14812218) to see how to implement login mechanism. – Izhaki Feb 12 '13 at 13:07

1 Answers1

1

Never write down unencrypted passwords. And also never send them via teh interwebs!

You can process your JSON in extjs like this (that is the question right?):

function checkJson(jsonString){
    var json = Ext.decode(jsonString);

    //json.form.login[0].username;
    //json.form.login[0].password;
}

But what @Izhaki said. This is bad javascript and these kind of checks should be done on the server-side.

A1rPun
  • 16,287
  • 7
  • 57
  • 90
  • Thanks for showing how to do this.. Can it be done using REST or without using server? (which is what I am interested in). I mean server will be there but I am thinking of using something like Web service(which I think is REST) to do json calls. – Mr_Green Feb 12 '13 at 15:27
  • I'm not too familiar with REST so I can't help you with this one but I guess you need a server to send your requests. – A1rPun Feb 13 '13 at 09:47
  • +1 you are right, that I need server support, which I am aware of. Any way I am searching about it now :). – Mr_Green Feb 13 '13 at 09:50