jeudi 1 janvier 2015

PHP logging in code


Is it possible to write a PHP log-in form with 2 fields (username and password) so that the web page wouldn't need any box?


It should work as a command line. (think about linux/ms-dos terminal)


To get an idea of what I am saying, the page should run like the following C code (just run it if you want to see what am I talking about):



#include <conio.h>
#include <stdio.h>

int main()
{
int DBl,i,tl;
struct DB //DB-database
{
char u[32];
char p[32];
};
char iu[32], ip[32];
//iu - input user; ip -input passowrd

//let's put some users in the database:
struct DB q[100];
sprintf(q[1].u,"%s","user");
sprintf(q[1].p,"%s","pass");
sprintf(q[2].u,"%s","admin");
sprintf(q[2].p,"%s","admin");
sprintf(q[3].u,"%s","username");
sprintf(q[3].p,"%s","password");

DBl=3; //database length
tl=5; //tries left
printf("Welcome to our website.\n");

while (tl!=0)
{
printf("\nusername: "); gets(iu);
printf("\n%s@password: ",iu);gets(ip);
//printf("\n");
for (i=1;i<=DBl;i++)
if(strcmp(q[i].u,iu)==0)
if (strcmp(q[i].p,ip)==0)
{
printf("logging in...");
return 1;
}
else break;
tl--;
printf("Wrong username and password!\n");
printf("Tries left: %d.\n",tl);
}
printf("Input blocked. Come back in 5 minutes!");

return 0;
}




Aucun commentaire:

Enregistrer un commentaire