NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <iostream>
#include <fstream>
#include <string>
#include <vector>


//Funkcijas deklarēšana
void registerUser();
void loginUser();

int main()
{

bool running = false;
while (!running)
{
// Lietotājam tiek dotas izvēles
std::cout << "Sveicināts login sistēmā!n";
std::cout << "Lūdzu, izvēlies vienu no minētājām opcijām:n";
std::cout << "1. Reģistrācijan";
std::cout << "2. Pieslēgšanāsn";
std::cout << "3. Iziešanan";

int choice;
std::cin >> choice;

switch (choice)
{
case 1:
registerUser();
break;
case 2:
loginUser();
break;
case 3:
std::cout << "Paldies, par jūsu apmeklējumu. Čavas (:";
running = true;
break;
default:
std::cout << "Nezināma izvēle, mēģini vēlreiz";
break;
}
}
return 0;
}


void registerUser()
{
// Tiek piedāvāta iespēja ievadīt vēlamo paroli un lietotājvārdu
std::string username, password;

std::cout << "Lūdzu, ievadiet savu lietotājvārdu: ";
std::cin >> username;
std::cout << "Lūdzu, ievadiet savu paroli: ";
std::cin >> password;

// Tiek atvērta lietotāju datubāze
std::ofstream userFile("users.txt", std::ios::app);


// Pārbauda vai fails tika atvērts bez problēmām
if (!userFile)
{
std::cerr << "Kļūda: nevar atvērt lietotāju datubāžu failu.n";
return;
}

// Ierakstīt lietotāja jauno informāciju failā
userFile << username << " " << password << std::endl;

// Faila aizvēršana
userFile.close();

// Paziņot par veiksmīgu reģistrāciju
std::cout << "Reģistrācija veiksmīga. Jūs tagad variet pievienoties.n";
}

void loginUser()
{
// Tiek piedāvāta iespēja ievadīt lietotājvārdu un paroli
std::string username, password;
std::cout << "Lūdzu, ievadiet savu lietotājvārdu: ";
std::cin >> username;
std::cout << "Lūdzu, ievadiet savu paroli: ";
std::cin >> password;

// Atvērt datubāžu failu nolasīšanai
std::ifstream userFile("users.txt");

// Pārbauda vai fails tika atvērts bez problēmām
if (!userFile)
{
std::cerr << "Kļūda: nevar atvērt lietotāju datubāžu failu.n";
return;
}

// Lasa lietotāju datubāžu failu ik pa rindiņai
std::string line;
std::vector<std::string> users;
while (getline(userFile, line))
{
// Atdalīt līniju lietotājvārdā un parolē izmantojot atstarpju noteicēju
size_t pos = line.find(" ");
std::string user = line.substr(0, pos);
std::string pass = line.substr(pos + 1);

// Pievienot lietotājvārdu pie visiem vārdiem
users.push_back(user);

// Pārbaudīt vai ievadītais lietotājvārds un parole sakrīt ar doto
if (user == username && pass == password)
{
std::cout << "Jūsu dati sakrīt. Sveicināti " << username << "!nn";
return;
}
}
// Ja lietotājs nav atrasts, paziņo un piedāva reģistrāciju
std::cout << "Pievienošanās neveiksmīga. Nederīgs lietotājvārds un vai parole.n";
std::cout << "Vai jūs vēlētos reģistrēties? (j/n)";
std::string choice;
std::cin >> choice;

if (choice == "j" || choice == "J")
{
registerUser();
}
else
{
std::cout << "Visu gaišu! (:'n";
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.