PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV Mobile (earlier versions) → Authentification par empreinte digitales WM 22 android (JAVA natif)
Authentification par empreinte digitales WM 22 android (JAVA natif)
Started by Monsieur CLAVIS, Oct., 04 2018 12:24 AM - No answer
Registered member
14 messages
Popularité : -1 (1 vote)
Posted on October, 04 2018 - 12:24 AM
Bonjour,

Jusqu'à la version 22 de WM, la fonction VérifieIdentitéUtilisateur() ne marche pas.
Je voudrais utiliser le lecteur d'empreintes malgré tout !

L'idée est d'implémenter un code JAVA d'authentification par empreintes digitales que j'ai trouvé sur internet.
C'est un code quoi fonctionne parfaitement sur ANDROID STUDIO et sur mon téléphone.

Je n'ai pas de bonnes notions sur le langage JAVA et j'aurais besoin de vos conseils pour intégrer ce code Java à windev mobile 22.

Le code JAVA comporte 2 classes :

import android.Manifest;
import android.app.KeyguardManager;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.CancellationSignal;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.security.KeyStore;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class MainActivity extends AppCompatActivity {

    private String KEY_NAME = "somekeyname";



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
        FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);

        if(!fingerprintManager.isHardwareDetected()) {
            Log.e("Hardware", "Finger print hardware not detected");
            return;
        }

        if(ContextCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT)
                != PackageManager.PERMISSION_GRANTED) {
            Log.e("Permission", "Fingerprint permission rejected");
            return;
        }

        if (!keyguardManager.isKeyguardSecure()) {
            Log.e("Keyguard", "Keyguard not enabled");
            return;

        }

        KeyStore keystore;

        try{
            keystore = KeyStore.getInstance("AndroidKeySTore");
        } catch (Exception e) {
            Log.e("KeyStore", e.getMessage());
            return;
        }

        KeyGenerator keyGenerator;

        try{
            keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
        } catch(Exception e) {
            Log.e("KeyGenerator", e.getMessage());
            return;
        }

        try{
            keystore.load(null);
            keyGenerator.init(
                    new KeyGenParameterSpec.Builder(KEY_NAME,
                            KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                            .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
                            .setUserAuthenticationRequired(true)
                            .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
                            .build());
            keyGenerator.generateKey();

            } catch(Exception e) {
                Log.e("Generating keys", e.getMessage());
                return;
        }

        Cipher cipher;

        try{
            cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES
            + "/" + KeyProperties.BLOCK_MODE_CBC
            + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
        } catch(Exception e) {
            Log.e("Cipher", e.getMessage());
            return;
        }

        try{
            keystore.load(null);
            SecretKey key = (SecretKey) keystore.getKey(KEY_NAME, null);
            cipher.init(Cipher.ENCRYPT_MODE, key);
        } catch(Exception e) {
            Log.e("Secret key", e.getMessage());
            return;
        }

        FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);

        CancellationSignal cancellationSignal = new CancellationSignal();
        fingerprintManager.authenticate(cryptoObject, cancellationSignal, 0, new AuthenticationHandler(this), null);
    }
}


Le code JAVA de la deuxième classe :

import android.hardware.fingerprint.FingerprintManager;
import android.widget.Toast;

public class AuthenticationHandler extends FingerprintManager.AuthenticationCallback {

    private MainActivity mainActivity;

    public AuthenticationHandler(MainActivity mainActivity) {
        this.mainActivity = mainActivity;
    }

    @Override
    public void onAuthenticationError(int errorCode, CharSequence errString) {
        super.onAuthenticationError(errorCode, errString);
        Toast.makeText(mainActivity, "Erreur d'authentification : " + errString, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
        super.onAuthenticationHelp(helpCode, helpString);
        Toast.makeText(mainActivity, "Aide d'authentification : " + helpString, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
        super.onAuthenticationSucceeded(result);
        Toast.makeText(mainActivity, "Accès autorisé !", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onAuthenticationFailed() {
        super.onAuthenticationFailed();
        Toast.makeText(mainActivity, "Accès non autorisé !", Toast.LENGTH_SHORT).show();
    }
}


J'aimerais savoir comment déclarer ces 2 classes dans Windev mobile 22 Android :

1 - pour la première classe JAVA dois-je faire :
public class FingerprintActivity extends AppCompatActivity {
}

ou bien :

public static void FingerprintActivity() extends AppCompatActivity {
}


2 - pour la deuxième classe JAVA dois-je faire :
public class FingerprintHandler extends FingerprintManager.AuthenticationCallback {
}

ou bien :

public static void FingerprintHandler() extends FingerprintManager.AuthenticationCallback {
}

--
Windev 20 windev mobile 20
Windows 7 64 bits