· 6 years ago · Jun 04, 2019, 12:18 PM
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace Classes_RegistarLogin10Contas
8{
9 class Program
10 {
11 // Constante para o tamanho da linha
12 static readonly int LARGURA = 50;
13
14 // Constante para os caracteres
15 static readonly char CARATER = '*';
16
17 // Constante para a margem
18 static readonly int MARGEM = 13;
19
20 static void Main(string[] args)
21 {
22 // CRIACAO DAS VARIAVEIS
23 string op1 = "1 - Login";
24 string op2 = "2 - Registar";
25 string sair = "0 - Sair";
26 int escolha = 99;
27 int verificarCellPhone = 99;
28 int verificarAll = 99;
29 int verificarLogins = 0;
30
31 //
32
33 string equalNome = "--";
34 string equalemail = "--";
35 string equalPassword = "--";
36 int equalNumber = 9999;
37
38 //
39 Utilizador utilizador = new Utilizador();
40
41 do
42 {
43 Console.Clear();
44
45 // CHAMA O MENU
46 menu(op1, op2, sair);
47
48 Console.WriteLine();
49
50 // ESPAÇO PARA A MARGEM
51 for (int i = 0; i < MARGEM; i++)
52 {
53 Console.Write(" ");
54 }
55
56 Console.Write("Escolha a opção : ");
57 escolha = Convert.ToInt32(Console.ReadLine());
58
59 switch (escolha)
60 {
61
62 #region LOGIN
63 case 1:
64
65 int escolhaCaso1 = 99;
66 // ESPAÇO PARA A MARGEM
67 for (int i = 0; i < MARGEM; i++)
68 {
69 Console.Write(" ");
70 }
71
72 Console.WriteLine();
73
74 // ESPAÇO PARA A MARGEM
75 for (int i = 0; i < MARGEM; i++)
76 {
77 Console.Write(" ");
78 }
79
80 Console.WriteLine("1 - Username");
81
82 // ESPAÇO PARA A MARGEM
83 for (int i = 0; i < MARGEM; i++)
84 {
85 Console.Write(" ");
86 }
87
88 Console.WriteLine("2 - Email");
89
90 // ESPAÇO PARA A MARGEM
91 for (int i = 0; i < MARGEM; i++)
92 {
93 Console.Write(" ");
94 }
95
96 Console.WriteLine("3 - Telemovel");
97
98 Console.WriteLine();
99
100 // ESPAÇO PARA A MARGEM
101 for (int i = 0; i < MARGEM; i++)
102 {
103 Console.Write(" ");
104 }
105
106 // PEDE E RECEBE A OPÇÃO
107 Console.Write("Das opções a cima qual quer usar para fazer o Login : ");
108 escolhaCaso1 = Convert.ToInt32(Console.ReadLine());
109
110 switch (escolhaCaso1)
111 {
112 case 1:
113
114 for (int i = 0; i < MARGEM; i++)
115 {
116 Console.Write(" ");
117 }
118
119 // PEDE O NOME
120 Console.Write("Introduza o username : ");
121 equalNome = Console.ReadLine();
122
123 for (int i = 0; i < 10 ; i++)
124 {
125 if (equalNome == utilizador.username[i])
126 {
127
128 for (int j = 0; j < MARGEM; j++)
129 {
130 Console.Write(" ");
131 }
132
133 Console.Write("Introduza a password : ");
134 equalPassword = Console.ReadLine();
135
136 if (equalPassword == utilizador.password[i])
137 {
138 for (int j = 0; j < MARGEM; j++)
139 {
140 Console.Write(" ");
141 }
142
143 Console.WriteLine("Login foi feito com sucesso.");
144 Console.ReadKey();
145
146
147 verificarAll = 0;
148
149 }
150 }
151
152 if ()
153
154 }
155
156 Console.WriteLine();
157
158
159
160 break;
161
162 case 2:
163
164 for (int i = 0; i < MARGEM; i++)
165 {
166 Console.Write(" ");
167 }
168
169 // PEDE O EMAIL
170 Console.Write("Introduza o email : ");
171 equalemail = Console.ReadLine();
172
173
174 for (int i = 0; i < 10; i++)
175 {
176 if (equalemail == utilizador.email[i])
177 {
178
179 for (int j = 0; j < MARGEM; j++)
180 {
181 Console.Write(" ");
182 }
183
184 Console.Write("Introduza a password : ");
185 equalPassword = Console.ReadLine();
186
187 if (equalPassword == utilizador.password[i])
188 {
189 for (int l = 0; l < MARGEM; l++)
190 {
191 Console.Write(" ");
192 }
193
194 Console.WriteLine("Login foi feito com sucesso.");
195 Console.ReadKey();
196
197
198 verificarAll = 0;
199
200 }
201 }
202 else
203 {
204
205 for (int j = 0; j < MARGEM; j++)
206 {
207 Console.Write(" ");
208 }
209
210 // DIZ Q O EMAIL N EXISTE.
211 Console.WriteLine("Email não existe");
212 Console.ReadKey();
213 Console.Clear();
214
215 }
216 }
217
218 Console.WriteLine();
219 break;
220
221 case 3:
222
223 for (int i = 0; i < MARGEM; i++)
224 {
225 Console.Write(" ");
226 }
227
228 // PEDE E RECEBE O NUMERO DO TELEMOVEL
229 Console.Write("Introduza o numero de telemovel : ");
230 equalNumber = Convert.ToInt32(Console.ReadLine());
231
232 for (int i = 0; i < 10; i++)
233 {
234 if (equalNumber == utilizador.cellphone[i])
235 {
236
237 for (int l = 0; l < MARGEM; l++)
238 {
239 Console.Write(" ");
240 }
241
242 // PEDE E RECEBE A PASSWORD
243 Console.Write("Introduza a password : ");
244 equalPassword = Console.ReadLine();
245
246 if (equalPassword == utilizador.password[i])
247 {
248 for (int j = 0; j < MARGEM; j++)
249 {
250 Console.Write(" ");
251 }
252
253 // APRESENTA QUE O LOGIN FOI FEITO COM SUCESSSO
254 Console.WriteLine("Login foi feito com sucesso.");
255 Console.ReadKey();
256
257
258 verificarAll = 0;
259
260 }
261 }
262 else
263 {
264
265 for (int j = 0; j < MARGEM; j++)
266 {
267 Console.Write(" ");
268 }
269
270 // DIZ Q O NUMERO N EXISTE
271 Console.WriteLine("Numero de telemovel não existe");
272 Console.ReadKey();
273 Console.Clear();
274
275 }
276 }
277
278 Console.WriteLine();
279
280 break;
281 }
282
283 break;
284 #endregion
285
286 #region REGISTAR
287 case 2:
288
289 int verificador123 = 999;
290
291 if (verificarLogins >= 10)
292 {
293 Console.WriteLine("Chegou ao limite maximo de logins");
294 }
295
296 for (int i = 0; i < MARGEM; i++)
297 {
298 Console.Write(" ");
299 }
300
301 Console.Write("Insira o nome de utilizador para registar : "); // pEDE E RECEBE O NOME
302 utilizador.username[verificarLogins] = Console.ReadLine();
303
304 Console.WriteLine();
305
306 #region PASSWORD
307 do
308 {
309
310 for (int i = 0; i < MARGEM; i++)
311 {
312 Console.Write(" ");
313 }
314
315 Console.WriteLine("Insira a password para registar (mais do que 3 carateres)"); // PEDE PARA INSERIR A PASSWORD.
316
317 for (int i = 0; i < MARGEM; i++)
318 {
319 Console.Write(" ");
320 }
321
322 utilizador.password[verificarLogins] = Console.ReadLine();
323
324
325 if (utilizador.password.Length < 3)
326 {
327
328 for (int i = 0; i < MARGEM; i++)
329 {
330 Console.Write(" ");
331 }
332
333 Console.WriteLine("A password têm de ter mais do que 3 carateres"); // VERIFICA A PASSWORD E AVISA Q TEM MENOS CARATERES
334 Console.WriteLine();
335
336 }
337 else
338 {
339 string verificarPassword = "=";
340
341 do
342 {
343
344 for (int i = 0; i < MARGEM; i++)
345 {
346 Console.Write(" ");
347 }
348
349 Console.WriteLine("Repita a password para verificar"); // PEDE E RECEBE A PASS A REPETIR
350
351 for (int i = 0; i < MARGEM; i++)
352 {
353 Console.Write(" ");
354 }
355
356 verificarPassword = Console.ReadLine();
357
358 for (int i = 0; i < MARGEM; i++)
359 {
360 Console.Write(" ");
361 }
362
363 Console.WriteLine("Password criada com sucesso."); // APRESENTA Q A PASS FOI CRIADA COM SUCCESS
364
365 }
366 while (verificarPassword != utilizador.password[verificarLogins]);
367 #endregion
368
369 Console.WriteLine();
370
371
372 #region EMAIL
373 int escolhaCaso2 = 99;
374
375 // APRESENTA A LISTA DE EMAILS.
376
377 // ESPAÇO PARA A MARGEM
378 for (int i = 0; i < MARGEM; i++)
379 {
380 Console.Write(" ");
381 }
382
383 Console.WriteLine("1 - @gmail.com");
384
385 // ESPAÇO PARA A MARGEM
386 for (int i = 0; i < MARGEM; i++)
387 {
388 Console.Write(" ");
389 }
390
391 Console.WriteLine("2 - @hotmail.com");
392
393 // ESPAÇO PARA A MARGEM
394 for (int i = 0; i < MARGEM; i++)
395 {
396 Console.Write(" ");
397 }
398
399 Console.WriteLine("3 - @yahoo.com");
400
401 Console.WriteLine();
402
403
404 int verificadorEmail = 99;
405
406 do
407 {
408
409 for (int i = 0; i < MARGEM; i++)
410 {
411 Console.Write(" ");
412 }
413
414 // PEDE A OPÇÃO PARA O EMAIL
415 Console.Write("Das opções a cima qual o dominio do seu email : ");
416 escolhaCaso2 = Convert.ToInt32(Console.ReadLine());
417
418 switch (escolhaCaso2)
419 {
420 case 1:
421
422 // DA ESPAÇO PARA A MARGEM
423 for (int i = 0; i < MARGEM; i++)
424 {
425 Console.Write(" ");
426 }
427
428 // PEDE E RECEBE O EMAIL
429 Console.Write("Insira o nome do seu gmail : ");
430 utilizador.email[verificarLogins] = Console.ReadLine() + "@gmail.com";
431
432 verificadorEmail = 0;
433
434 break;
435
436 case 2:
437
438 // DA ESPAÇO PARA A MARGEM
439 for (int i = 0; i < MARGEM; i++)
440 {
441 Console.Write(" ");
442 }
443
444 // PEDE E RECEBE O EMAIL
445 Console.Write("Insira o nome do seu hotmail : ");
446 utilizador.email[verificarLogins] = Console.ReadLine() + "@hotmail.com";
447
448 verificadorEmail = 0;
449
450 break;
451
452 case 3:
453
454 // DA ESPAÇO PARA A MARGEM
455 for (int i = 0; i < MARGEM; i++)
456 {
457 Console.Write(" ");
458 }
459
460 // PEDE E RECEBE O EMAIL
461 Console.Write("Insira o nome do seu yahoo : ");
462 utilizador.email[verificarLogins] = Console.ReadLine() + "@yahoo.com";
463
464 verificadorEmail = 0;
465
466 break;
467
468 default:
469
470 for (int i = 0; i < MARGEM; i++)
471 {
472 Console.Write(" ");
473 }
474
475 Console.WriteLine("Opção invalida!");
476 Console.WriteLine();
477
478 break;
479
480 }
481 }
482 while (verificadorEmail != 0);
483
484 #endregion
485
486 Console.WriteLine();
487
488
489 ///////////////////////////////7
490
491 string telemovelLength = "0";
492
493 do
494 {
495 for (int i = 0; i < MARGEM; i++)
496 {
497 Console.Write(" ");
498 }
499
500 // PEDE E RECEBE O NUMERO DO TELEMOVEL
501 Console.Write("Insira o seu numero de telemovel : ");
502 utilizador.cellphone[verificarLogins] = Convert.ToInt32(Console.ReadLine());
503
504 telemovelLength = Convert.ToString(utilizador.cellphone);
505
506 if (telemovelLength.Length < 9)
507 {
508
509 for (int i = 0; i < MARGEM; i++)
510 {
511 Console.Write(" ");
512 }
513
514 Console.WriteLine("Numero invalido"); // CASO O NUMERO SEJA INVALIDO
515 Console.WriteLine();
516 }
517 else
518 {
519 verificarCellPhone = 0;
520 Console.WriteLine();
521 }
522 }
523 while (verificarCellPhone != 0);
524 ///////////////////////////////7
525
526 verificarLogins = verificarLogins + 1;
527
528 // DA ESPAÇO DA MARGEM
529 for (int i = 0; i < MARGEM; i++)
530 {
531 Console.Write(" ");
532 }
533
534 Console.WriteLine("Registado com sucesso!"); // APRESENTA NO ECRA REGISTO COM SUCESSO
535
536 Console.ReadKey();
537 Console.Clear();
538
539 verificador123 = 0;
540 }
541
542 }
543 while (verificador123 != 0);
544 break;
545
546 #endregion
547
548 // CASO 0 FECHA O PROGRAMA
549 case 0:
550
551 Console.WriteLine();
552
553 for (int i = 0; i < MARGEM; i++)
554 {
555 Console.Write(" ");
556 }
557
558 Console.WriteLine("O programa vai fechar.");
559 Console.WriteLine();
560
561 verificarAll = 0;
562
563 break;
564 }
565
566 }
567
568 while (verificarAll != 0);
569 Console.WriteLine();
570 }
571
572
573 #region menu
574 static void peca1()
575 {
576
577 // Da espaço para a margem
578 for (int i = 0; i < MARGEM; i++)
579 {
580 Console.Write(" ");
581 }
582
583 // Faz a linha com os carateres
584 for (int i = 0; i < LARGURA; i++)
585 {
586 Console.Write(CARATER);
587 }
588
589 // Da espaço
590 Console.WriteLine();
591 }
592
593 static void peca2()
594 {
595 // Da espaço para a margem
596 for (int i = 0; i < MARGEM; i++)
597 {
598 Console.Write(" ");
599 }
600
601 // Desenha o carater
602 Console.Write(CARATER);
603
604 // Da espaço em branco no meio dos carateres
605 for (int i = 0; i < LARGURA - 2; i++)
606 {
607 Console.Write(" ");
608 }
609
610 // Desenha o carater
611 Console.Write(CARATER);
612
613 // Da espaço
614 Console.WriteLine();
615 }
616
617 static void peca3(string opcao)
618 {
619 // Da espaço para a margem
620 for (int i = 0; i < MARGEM; i++)
621 {
622 Console.Write(" ");
623 }
624
625 // Desenha o carater
626 Console.Write(CARATER);
627
628 // Da espaço em branco no meio dos carateres
629 for (int i = 0; i < (LARGURA - opcao.Length) / 2; i++)
630 {
631 Console.Write(" ");
632 }
633
634 Console.Write(opcao);
635
636
637 // Da espaço em branco no meio dos carateres
638 for (int i = 0; i < (LARGURA - opcao.Length) / 2 - 2; i++)
639 {
640 Console.Write(" ");
641 }
642
643 Console.Write(CARATER);
644 }
645
646 static void peca4(string opcao)
647 {
648 // Da espaço para a margem
649 for (int i = 0; i < MARGEM; i++)
650 {
651 Console.Write(" ");
652 }
653
654 // Desenha o carater
655 Console.Write(CARATER);
656
657 // Da espaço em branco no meio dos carateres
658 for (int i = 0; i < (LARGURA - opcao.Length) / 2; i++)
659 {
660 Console.Write(" ");
661 }
662
663 Console.Write(opcao);
664
665
666 // Da espaço em branco no meio dos carateres
667 for (int i = 0; i < (LARGURA - opcao.Length) / 2 - 2; i++)
668 {
669 Console.Write(" ");
670 }
671 Console.Write(" ");
672
673 Console.Write(CARATER);
674 }
675
676 static void peca5(string opcao)
677 {
678 // Da espaço para a margem
679 for (int i = 0; i < MARGEM; i++)
680 {
681 Console.Write(" ");
682 }
683
684 // Desenha o carater
685 Console.Write(CARATER);
686
687 // Da espaço em branco no meio dos carateres
688 for (int i = 0; i < (LARGURA - opcao.Length) / 2; i++)
689 {
690 Console.Write(" ");
691 }
692
693 Console.Write(opcao);
694
695
696 // Da espaço em branco no meio dos carateres
697 for (int i = 0; i < (LARGURA - opcao.Length) / 2 - 2 + 1; i++)
698 {
699 Console.Write(" ");
700 }
701
702 Console.Write(CARATER);
703 }
704
705 static void menu(string op1, string op2, string sair)
706 {
707
708 peca1();
709 peca2();
710 peca5(op1);
711
712 Console.WriteLine();
713 peca2();
714 peca3(op2);
715
716 Console.WriteLine();
717 peca2();
718 peca3(sair);
719
720 Console.WriteLine();
721 peca2();
722 peca1();
723
724 }
725 #endregion
726 }
727}