A brand new core
using PassWordsCore;
//Your code logic
//Initialize db
Database.EnsureCreated();
//Create PassWords database
Database.CreateDB("YourDBName","YourPassword");
static Database db = new Database();
db.Login("YourDBName","YourPassword");
//Create account object
var account = new Account()
{
Username = "Test",
Password = "Test123",
Title = "MyAccount",
Description = "Test the account",
Type = "Email"
};
//Add account to current database
db.Add(account);
List<Account> accounts = db.GetAccounts();
var testaccount = accounts.FirstOrDefault(a => a.Title == "MyAccount");
testaccount.Title = "HelloWorld";
db.Update(testacccount);
var testaccount = accounts.First(a => a.Title == "MyAccount");
db.Delete(testacccount);
db.UpdatePassword("oldpass","newpass");
db.UpdateName("NewDBName");
db.Backup("destinationpath/database.db");
Database.Restore("destinationpath/database.db","MyDatabase");
Database.DeleteDB("YourDBName");
List<DB> alldatabases = Database.ListDatabases();
Database.EnsureDeleted();
You can use 2FA for making the login to the database more secure, but you can also use PassWords to validate a 2FA login into another system.
//First, login into your database
static Database db = new Database();
db.Login("YourDBName","YourPassword");
//Second, enable 2FA login
db.Add2FA();
//Third, get your secret
//Use this secret into another 2FA app
string secret = db.Get2FA();
//Logout
db.Logout();
//When you login now,
db.Login("YourDBName","YourPassword");
//you will get
LoginResult.Needs2FA;
//Now you have to use your 2FA app and enter the code:
db.Login2FA("000000");//your code
//If returns true, you are logged in
//Remove 2FA from database: (first login() and login2fa())
db.Remove2FA();
//First, update an account and set the TwoFactorSecret property to your secret
var testaccount = accounts.First(a => a.Title == "MyAccount");
testaccount.TwoFactorSecret = "MYSECRET";
//Second, login into an application with MyAccount
//Generate key (remember => every 30 seconds it changes so you have to generate a new one)
string code = Database.GenerateCode("MYSECRET");
//Enter the code and log in.
Database.RandomString(10,true); //Length = 10, letters = true
Database.RandomString(15,true,true,true,true); //Length = 15, letters, capitals numbers and special chars