Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // TGB2
- //
- // Created by Gabriel Schütz and Vinicius Müller on 16.11.17.
- // Copyright © 2017 Gabriel Schütz and Vinicius Müller. All rights reserved.
- //
- #include <stdio.h>
- #include <strings.h>
- #include <time.h>
- #include <locale.h>
- typedef struct elemento {
- char dado[50];
- struct elemento *proximo;
- } elemento;
- elemento *topo = NULL;
- elemento *alocar = NULL;
- int push(char *dado) {
- alocar = (struct elemento *) malloc(sizeof(struct elemento));
- if (alocar == NULL) {
- printf("Falta de memória\n");
- exit(0);
- }
- sprintf(alocar->dado,"%s",dado);
- if (topo == NULL) {
- topo = alocar;
- topo->proximo = NULL;
- }
- else
- {
- alocar->proximo = topo;
- topo = alocar;
- }
- }
- int logar(char * usu, char * sen){
- FILE *pArq;
- if((pArq = fopen("db.txt", "r")) == NULL){
- return 0;
- }
- char user[100], pass[100];
- while(fgetc(pArq) != EOF){
- fseek(pArq, -1, SEEK_CUR );
- fscanf(pArq, "%[^,], %s\n", user, pass);
- if (strcmp(usu, user) == 0){
- if (strcmp(pass, sen) == 0){
- return 1;
- }
- }
- }
- return 0;
- }
- void mostrar(void)
- {
- elemento *aux = topo;
- while(aux)
- {
- printf("%s\n", aux->dado);
- aux = aux->proximo;
- }
- }
- int main(int argc, const char * argv[]) {
- printf("Bem-vindo. Digite:\n1 - Para entrar.\n2 - Para mostrar usuários autenticados.\n");
- char a, usuario[100], senha[30];
- while(1)
- {
- a = getchar();
- fflush(stdin);
- switch (a)
- {
- case '1':
- printf("Entrar\nUsuario: ");
- fflush(stdin);
- gets(usuario);
- printf("senha: ");
- fflush(stdin);
- gets(senha);
- if(logar(usuario, senha) == 1)
- {
- time_t t = time(NULL);
- time(&t);
- struct tm *timeinfo = localtime (&t);
- sprintf(usuario,"%s %02d/%02d/%02d %02d:%02d\n", usuario,timeinfo->tm_mday,
- timeinfo->tm_mon+1, (timeinfo->tm_year - 100), timeinfo->tm_hour, timeinfo->tm_min);
- push(usuario);
- printf("Usuário autenticado com sucesso \n");
- }else
- printf("ACESSO NEGADO\n");
- printf("Digite:\n1 - Para entrar.\n2 - Para mostrar usuários autenticados.\n");
- break;
- case '2':
- printf("Mostrar\n");
- mostrar();
- printf("Digite:\n1 - Para entrar.\n2 - Para mostrar usuários autenticados.\n");
- default:
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement