IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Créer une page de login


Sujet :

Android

  1. #1
    Candidat au Club
    Homme Profil pro
    Technicien réseaux et télécoms
    Inscrit en
    Mai 2014
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Technicien réseaux et télécoms
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Mai 2014
    Messages : 6
    Points : 4
    Points
    4
    Par défaut Créer une page de login
    Bonjour à tous,

    je voudrais créer une appli sur android où l'utilisateur devra d'abord s'identifier avant d'avoir accès à l'appli et je suis bloqué au niveau de la page de login

    l'appli doit se connecter à une base de données mysql pour vérifier via un script php si les identifiants entrés sont bien correctes et ouvrir la page d'accueil si oui, afficher une boite de dialogue si non

    j'ai parcouru plusieurs tutos mais sans succès

    Voici mon code:

    Script php :

    Code Php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    <?php
     
    $hostname_localhost ="localhost";
    $database_localhost ="acms_db";
    $username_localhost ="root";
    $password_localhost ="";
     
    $localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost) or trigger_error(mysql_error(),E_USER_ERROR); 
     
    mysql_select_db($database_localhost,$localhost);
     
    $useremail = $_POST['UserEmail'];
    $password = $_POST['Password'];
     
     $query_search = "select * from utilisateur where username = '".$useremail."' AND password = '".$password. "'";
     $query_exec = mysql_query($query_search) or die(mysql_error());
     $rows = mysql_num_rows($query_exec);
     
     if($rows --> 0) 
     { 
    	echo "Y"; 
    }else  {
    	echo "N"; 
    }
    ?>

    Code Java :

    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    package com.mbs.acmsmobilesoft;
     
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.List;
     
    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;
     
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.ProgressDialog;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.preference.PreferenceManager;
    import android.view.View;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
     
    public class ConnexionActivity extends Activity{
     
    	// Lien vers votre page php sur votre serveur
    	//private static final String	UPDATE_URL	= "http://192.168.249.1/ACMS_Project/connexion.php";
     
    	Button login;
    	String name="",pass="";
    	EditText username,password;
    	TextView tv;
    	byte[] data;
    	HttpPost httppost;
    	StringBuffer buffer;
    	HttpResponse response;
    	HttpClient httpclient;
    	InputStream inputStream;
    	SharedPreferences app_preferences ;
    	List<NameValuePair> nameValuePairs;
    	CheckBox check;
     
    	ProgressDialog progressDialog;
     
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		// TODO Auto-generated method stub
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.connexion_layout);
     
    		// initialisation d'une progress bar
    		progressDialog = new ProgressDialog(this);
    		progressDialog.setMessage("Connexion en cour...");
    		progressDialog.setIndeterminate(true);
    		progressDialog.setCancelable(false);
     
    		app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
    		username = (EditText) findViewById(R.id.username);
    		password = (EditText) findViewById(R.id.password);
    		login = (Button) findViewById(R.id.connexion);
    		check = (CheckBox) findViewById(R.id.check);
     
    		String Str_user = app_preferences.getString("username","0" );
    		String Str_pass = app_preferences.getString("password", "0");
    		String Str_check = app_preferences.getString("checked", "no");
     
    		if(Str_check.equals("yes")){
    			username.setText(Str_user);
    			password.setText(Str_pass);
    			check.setChecked(true);
    		}
     
    		login.setOnClickListener(new View.OnClickListener(){
    			@Override
    			public void onClick(View v){
     
    				name = username.getText().toString();
    				pass = password.getText().toString();
    				String Str_check2 = app_preferences.getString("checked", "no");
     
    				if(Str_check2.equals("yes")){
    					SharedPreferences.Editor editor = app_preferences.edit();
    					editor.putString("username", name);
    					editor.putString("password", pass);
    					editor.commit();
    				}
    				if(name.equals("") || pass.equals("")){
    					Toast.makeText(ConnexionActivity.this, "Blank Field..Please Enter", Toast.LENGTH_LONG).show();
    					createDialog("Erreur", "Entrez le nom utilisateur et ou le mot de passe");
    				}
    				else{
    					progressDialog.show();
     
     
    					try {
    						httpclient = new DefaultHttpClient();
    						httppost = new HttpPost("http://192.168.249.1/ACMS_Project/connexion.php");
    						// Add your data
    						nameValuePairs = new ArrayList<NameValuePair>(2);
    						nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));
    						nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));
    						httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
     
    						// Execute HTTP Post Request
    						response = httpclient.execute(httppost);
    						inputStream = response.getEntity().getContent();
     
    						data = new byte[256];
     
    						buffer = new StringBuffer();
    						int len = 0;
    						while (-1 != (len = inputStream.read(data)) ){
    							buffer.append(new String(data, 0, len));
    						}
     
    						inputStream.close();
    					}
     
    					catch (Exception e){
    						Toast.makeText(ConnexionActivity.this, "error"+e.toString(), Toast.LENGTH_LONG).show();
    					}
    					if(buffer.charAt(0)=='Y'){
    						progressDialog.dismiss();
    						Toast.makeText(ConnexionActivity.this, "login successfull", Toast.LENGTH_LONG).show();
    						Toast.makeText(ConnexionActivity.this, "res "+buffer.charAt(0)+",", Toast.LENGTH_LONG).show();
    					}
    					else{
    						progressDialog.dismiss();
    						Toast.makeText(ConnexionActivity.this, "Invalid Username or password", Toast.LENGTH_LONG).show();
    						Toast.makeText(ConnexionActivity.this, "res "+buffer.charAt(0)+",", Toast.LENGTH_LONG).show();
    						createDialog("Erreur", "Nom utilisateur/mot de passe incorrecte");
    					}
    				}
    			}
    		});
     
    		check.setOnClickListener(new View.OnClickListener(){
    			public void onClick(View v){
    				// Perform action on clicks, depending on whether it's now checked
    				SharedPreferences.Editor editor = app_preferences.edit();
    				if (((CheckBox) v).isChecked()){
     
     
    					editor.putString("checked", "yes");
    					editor.commit();
    				}else{
    					editor.putString("checked", "no");
    					editor.commit();
    				}
    			}
    		});
     
    	}
    	public void Move_to_next(){
     
    		//  startActivity(new Intent(this, zzz.class));
    	}
     
    	private void createDialog(String title, String text){
    		// Création d'une popup affichant un message
    		AlertDialog ad = new AlertDialog.Builder(this).setPositiveButton("Ok", null).setTitle(title).setMessage(text).create();
    		ad.show();
     
    	}
    }

    La réponse à la requête : (buffer.charAt(0)) est supposée être un "Y" ou un "N" mais il s'agit plutôt du symbole "<", En vérifiant je me sui rendu compte que la réponse est du html du genre <!DOCTYPE ...,

    je ne sais pas à quel niveau il y a problème

    Je voudrais également afficher une progressDialog pendant le traitement de la requête juste après le click sur le bouton "login" mais il ne s'affiche pas.

    Quelqu'un pourrait-il m'aider ?
    merci

  2. #2
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2013
    Messages
    273
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2013
    Messages : 273
    Points : 150
    Points
    150
    Par défaut
    Citation Envoyé par ing_ndjana Voir le message
    j'ai parcouru plusieurs tutos mais sans succès
    j'ai deja suivi un tuto pour ce genre d'appli http://microlabs.niloo.fr/?p=211 il avait bien marché mis a part une petite erreur, regarde cette discussion pour corriger l'erreur et ensuite ça devrai bien marcher http://www.developpez.net/forums/d14...ption-android/

Discussions similaires

  1. Réponses: 1
    Dernier message: 08/09/2008, 16h27
  2. Peut-on créer une page internet via JBuilder?
    Par Xavier dans le forum JBuilder
    Réponses: 2
    Dernier message: 17/02/2005, 22h21
  3. [servlet][jsp] Creer une page de login
    Par Beuj dans le forum Servlets/JSP
    Réponses: 3
    Dernier message: 19/03/2004, 18h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo