Skip to content
Snippets Groups Projects
Commit a67cd413 authored by Tharun kumar's avatar Tharun kumar
Browse files

Upload New File

parent 6fbdcdbb
Branches
No related tags found
No related merge requests found
package com.example.fund_restart;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.DialogInterface;
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.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
EditText email,password;
Button loginbutton;
TextView register,logintext,admin_login;
SQLiteDatabase d;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
logintext = findViewById(R.id.logintext);
email = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
admin_login = findViewById(R.id.adminlog);
register = findViewById(R.id.register);
register.setOnClickListener(this);
logintext.setOnClickListener(this);
admin_login.setOnClickListener(this);
d = openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
}
@Override
public void onClick(View v) {
if(v.getId() == R.id.adminlog){
Intent admin = new Intent(this,Adminpre.class);
startActivity(admin);
}
if(v.getId() == R.id.register){
Intent register_intent = new Intent(this,Register.class);
startActivity(register_intent);
}
if(v.getId() == R.id.logintext){
if(email.getText().toString().isEmpty() || password.getText().toString().isEmpty()) {
{
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle("Alert");
alertDialog.setMessage("Fill all the details");
alertDialog.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}}
else
{
Cursor cus=d.rawQuery("SELECT count(email) FROM student WHERE email ='" + email.getText() + "'", null);
if(cus.moveToFirst())
{
if(cus.getInt(0)>=1)
{
Cursor cu = d.rawQuery("SELECT password FROM student WHERE email='" + email.getText() + "'", null);
if (cu.moveToFirst()) {
// Displaying record if found

if (cu.getString(0).equals(password.getText().toString()) ) {
Toast.makeText(getApplicationContext(), "Logging in....", Toast.LENGTH_SHORT).show();
Intent x = new Intent(MainActivity.this, Login.class);
startActivity(x);
}
else {
showMessage("Error", "Invalid password");
password.setText("");
}
}
cu.close();
}
else if(cus.getInt(0)==0)
{
showMessage("Create an account first", "No account found in this name");
}
}
cus.close();}
}
}
private void showMessage(String error, String invalid_password) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(error);
builder.setMessage(invalid_password);
builder.show();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment