import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class Login extends AppCompatActivit {
Button reg;
Button login;
TextView em, ps;
String eid, pass;
SQLiteDatabase db;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.login );
db = openOrCreateDatabase( "my.db", MODE_PRIVATE, null );
db.execSQL( "create table if not exists user(id integer primary key autoincrement,uname text,phone text,dob text,email text,pass text, gender text,city text)" );
reg = findViewById( R.id.reg );
login = findViewById( R.id.login );
em = findViewById( R.id.em );
ps = findViewById( R.id.ps );
reg.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
eid = em.getText().toString();
pass = ps.getText().toString();
Toast.makeText( Login.this, eid, Toast.LENGTH_SHORT ).show();
Toast.makeText( Login.this, pass, Toast.LENGTH_SHORT ).show();
Intent Intent = new Intent( Login.this, Regdata.class );
startActivity( Intent );
}
} );
login.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
eid = em.getText().toString();
pass = ps.getText().toString();
Cursor cursor = db.rawQuery( "select * from user where email='" + eid + "' and pass='" + pass + "'", null );
if (cursor != null) {
if (cursor.moveToNext()) {
Toast.makeText( Login.this, "Login done", Toast.LENGTH_SHORT ).show();
} else {
Toast.makeText( Login.this, "Invalid", Toast.LENGTH_SHORT ).show();
}
}
}
} );
}
@Override
protected void onStart() {
super.onStart();
}
}
Comments
Post a Comment