Android 四位数字密码验证器类(带界面)

第一次发文章,如有错误请多包涵,感谢指正。

请勿用于商业用途。

使用方法:

//调用
    String RIGHT_PASSWORD = "1234";
    Intent intentSet = new Intent(MainActivity.this, password_input.class);
    Bundle bundle = new Bundle();
    bundle.putString("right_password", RIGHT_PASSWORD);
    intentSet.putExtras(bundle);
    startActivityForResult(intentSet, 1);

//处理是否通过密码验证
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        password_correct = data.getExtras().getBoolean("password_correct");//得到新Activity 关闭后返回的数据
        if(password_correct){
            //密码输入正确
        }else{
            //密码输入错误
        }
    }

I.password_input.java

package com.example.safesystem;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

public class password_input extends AppCompatActivity {
    String input_password = "";
    String right_password = "";
    boolean password_correct=false;
    int tmp = 0;

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

        hideBottomUIMenu();
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        passwordNumboard();

    }

    public void passwordNumboard(){
        input_password = "";
        right_password = getIntent().getStringExtra("right_password");
        //TODO: 做密码验证器

        List<TextView> numButton = new ArrayList<TextView>();
        numButton.add((TextView) findViewById(R.id.button_num0));
        numButton.add((TextView) findViewById(R.id.button_num1));
        numButton.add((TextView) findViewById(R.id.button_num2));
        numButton.add((TextView) findViewById(R.id.button_num3));
        numButton.add((TextView) findViewById(R.id.button_num4));
        numButton.add((TextView) findViewById(R.id.button_num5));
        numButton.add((TextView) findViewById(R.id.button_num6));
        numButton.add((TextView) findViewById(R.id.button_num7));
        numButton.add((TextView) findViewById(R.id.button_num8));
        numButton.add((TextView) findViewById(R.id.button_num9));


        numButton.get(0).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                input_password+=0;
                displayUpdate();
            }
        });
        numButton.get(1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                input_password+=1;
                displayUpdate();
            }
        });
        numButton.get(2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                input_password+=2;
                displayUpdate();
            }
        });
        numButton.get(3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                input_password+=3;
                displayUpdate();
            }
        });
        numButton.get(4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                input_password+=4;
                displayUpdate();
            }
        });
        numButton.get(5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                input_password+=5;
                displayUpdate();
            }
        });
        numButton.get(6).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                input_password+=6;
                displayUpdate();
            }
        });
        numButton.get(7).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                input_password+=7;
                displayUpdate();
            }
        });
        numButton.get(8).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                input_password+=8;
                displayUpdate();
            }
        });
        numButton.get(9).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                input_password+=9;
                displayUpdate();
            }
        });


        ((ImageView)findViewById(R.id.button_back)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(input_password.length()>=1){
                    input_password = input_password.substring(0,input_password.length()-1);
                }
                displayUpdate();
            }
        });

        ((ImageView)findViewById(R.id.button_ok)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                password_correct = input_password.equals(right_password);
                Intent intent = new Intent();
                Bundle bundleRet = new Bundle();
                bundleRet.putBoolean("password_correct",password_correct);
                //把返回数据存入Intent
                intent.putExtras(bundleRet);
                //设置返回数据
                password_input.this.setResult(RESULT_OK, intent);
                //关闭Activity
                password_input.this.finish();
            }
        });
    }

    void displayUpdate(){
        switch (input_password.length()){
            case 0:
                ((ImageView)findViewById(R.id.password_1)).setImageResource(R.drawable.pic_password_notclicked);
                ((ImageView)findViewById(R.id.password_2)).setImageResource(R.drawable.pic_password_notclicked);
                ((ImageView)findViewById(R.id.password_3)).setImageResource(R.drawable.pic_password_notclicked);
                ((ImageView)findViewById(R.id.password_4)).setImageResource(R.drawable.pic_password_notclicked);
                break;
            case 1:
                ((ImageView)findViewById(R.id.password_1)).setImageResource(R.drawable.pic_password_clicked);
                ((ImageView)findViewById(R.id.password_2)).setImageResource(R.drawable.pic_password_notclicked);
                ((ImageView)findViewById(R.id.password_3)).setImageResource(R.drawable.pic_password_notclicked);
                ((ImageView)findViewById(R.id.password_4)).setImageResource(R.drawable.pic_password_notclicked);
                break;
            case 2:
                ((ImageView)findViewById(R.id.password_1)).setImageResource(R.drawable.pic_password_clicked);
                ((ImageView)findViewById(R.id.password_2)).setImageResource(R.drawable.pic_password_clicked);
                ((ImageView)findViewById(R.id.password_3)).setImageResource(R.drawable.pic_password_notclicked);
                ((ImageView)findViewById(R.id.password_4)).setImageResource(R.drawable.pic_password_notclicked);
                break;
            case 3:
                ((ImageView)findViewById(R.id.password_1)).setImageResource(R.drawable.pic_password_clicked);
                ((ImageView)findViewById(R.id.password_2)).setImageResource(R.drawable.pic_password_clicked);
                ((ImageView)findViewById(R.id.password_3)).setImageResource(R.drawable.pic_password_clicked);
                ((ImageView)findViewById(R.id.password_4)).setImageResource(R.drawable.pic_password_notclicked);
                break;
            case 4:
                ((ImageView)findViewById(R.id.password_1)).setImageResource(R.drawable.pic_password_clicked);
                ((ImageView)findViewById(R.id.password_2)).setImageResource(R.drawable.pic_password_clicked);
                ((ImageView)findViewById(R.id.password_3)).setImageResource(R.drawable.pic_password_clicked);
                ((ImageView)findViewById(R.id.password_4)).setImageResource(R.drawable.pic_password_clicked);
                break;
        }
        if(input_password.length()==4){
            password_correct = input_password.equals(right_password);
            Intent intent = new Intent();
            Bundle bundleRet = new Bundle();
            bundleRet.putBoolean("password_correct",password_correct);
            //把返回数据存入Intent
            intent.putExtras(bundleRet);
            //设置返回数据
            password_input.this.setResult(RESULT_OK, intent);
            //关闭Activity
            password_input.this.finish();
        }
    }


    protected void hideBottomUIMenu() {
        //隐藏虚拟按键,并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }

}

II.activity_password_input.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".password_input">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000"
        app:layout_constraintVertical_weight="1"
        app:layout_constraintHorizontal_weight="1"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/imageView8"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="3" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/password_space_left"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />

                <ImageView
                    android:id="@+id/password_1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:src="@drawable/pic_password_notclicked" />

                <ImageView
                    android:id="@+id/password_2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:src="@drawable/pic_password_notclicked" />

                <ImageView
                    android:id="@+id/password_3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:src="@drawable/pic_password_notclicked" />

                <ImageView
                    android:id="@+id/password_4"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:src="@drawable/pic_password_notclicked" />

                <ImageView
                    android:id="@+id/password_space_right"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/button_num1"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:text="1"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />

                <Button
                    android:id="@+id/button_num2"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:text="2"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />

                <Button
                    android:id="@+id/button_num3"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:text="3"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />

                <ImageView
                    android:id="@+id/button_back"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:src="@drawable/pic_password_back"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/button_num4"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:text="4"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />

                <Button
                    android:id="@+id/button_num5"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:text="5"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />

                <Button
                    android:id="@+id/button_num6"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:text="6"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />

                <Button
                    android:id="@+id/button_num0"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:text="0"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/button_num7"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:text="7"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />

                <Button
                    android:id="@+id/button_num8"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:text="8"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />

                <Button
                    android:id="@+id/button_num9"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:text="9"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />

                <ImageView
                    android:id="@+id/button_ok"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:src="@drawable/pic_password_ok"
                    android:textColor="#FFFFFF"
                    android:textSize="25pt" />
            </LinearLayout>

        </LinearLayout>

        <ImageView
            android:id="@+id/imageView9"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="3" />
    </LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

用于对付FUN49加密的4位密码直读软件终于问世了。区别于早期的先删除程序开端AR1001,然后再重新写入,以达到读出密码的假直读方式。菜鸟信以为真,以为是直读,但是高手都知道其实还是用了密码删除法,先删除掉程序的开端,然后读出密码,而后再重新写入。这样做确实可以读到密码,但是一个巨大的风险来了,就是要删除程序开端,删除版能安全吗? 大家注意区分真直读和假直读,真直读是在plc的运行状态就可以直接迅速的读出密码来,无需停机,假直读呢是要求你必须在编程状态或者监控状态才可以读密码,这就是假直读,改变状态的原因是他要删除你的程序的开端,然而在运行状态是删除不了的,所以假直读说白了还是密码删除版的变种。辨别真直读假直读的方法就是把CQM1系列PLC的DIP开关1置ON,CPM1系列PLC的DM6602第0位置1,使其具有写保护功能,看看是否还能读出密码来,不能读就是假直读,删除版的,能读就是真直读。 本坛又一力作,经过几天的努力终于制作了这个真正的在运行状态下直读密码,无需停机,又安全快捷的解密软件。不但可以破解AR1001加密,还可以破解AR1002程序段加密,此软件可解CQM1H C200H,C200HS, C1000H, C2000H, CPM1, CPM2*-S*, CQM1、CPM1A、CPM2A等系列,可解C系列四位密码,瞬间显示密码,关键词:直读版,非穷举法解密,速度快 注:有哪位网友测试不成功的,或者有什么问题的,可以联系我给你远程调试,保证上述型号都可以运行直读。加我QQ:596181637,基本24小时在线。 通讯错误问题: 最近有很多网友打电话询问软件连接不了,每天都有,今天给予一一解答 。关于错误的原因系统会弹出对话框,对话框里面就是错误的原因,由于是英文的,所以很多人看不懂。今天一一说明。第一种就是 8002 错误 ,你翻译一下就知道了,这是未找到端口错误,软件未找到你设置的com端口,软件打开默认com1,如果您使用的电脑没有串口,是usb转换的虚拟串口,那么这个问题就经常出现,但是你右单击你的电脑,点击属性,看硬件设置里面,看看您的电脑的usb转232的虚拟COM端口号是多少,软件的com号就设置多少,就没问题了。总结:8002端口未找到。 再一个就是 8005错误,这个问题您的电脑也会弹出明确的错误原因,意思是说端口已被占用,你再打开这个软件之前 已经打开了占用这个端口的其他软件,比如编程软件,一个串口不可能同时被两个软件使用的。如果你先打开了解密软件,您的编程软件也用不了啦。总结:8005端口被占用。 再一个就是 “Mscomm32.ocx”错误,这个你要是搞不定说明你从未搞过解密,是第一次
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值