public IActionResult SignUp(mltSignUpViewModel mltSignUpViewModel) { string signPrivateKey = null, agreePrivateKey = null, signPublicKey = null, agreePublicKey = null; Assets <UserCredAssetData> userAsset = _bigChainDbService.GetUserAssetFromTypeID(AssetType.Doctor, mltSignUpViewModel.CSMLSID); if (userAsset != null) { ModelState.AddModelError("", "A Doctor profile with that MINC already exists"); return(View(mltSignUpViewModel)); } var passphrase = mltSignUpViewModel.MLTKeyWord; var password = mltSignUpViewModel.Password; EncryptionService.getNewBlockchainUser(out signPrivateKey, out signPublicKey, out agreePrivateKey, out agreePublicKey); var userAssetData = new UserCredAssetData { FirstName = mltSignUpViewModel.FirstName, LastName = mltSignUpViewModel.LastName, ID = mltSignUpViewModel.CSMLSID, Email = mltSignUpViewModel.Email, PrivateKeys = EncryptionService.encryptPrivateKeys(mltSignUpViewModel.CSMLSID, passphrase, signPrivateKey, agreePrivateKey), DateOfRecord = DateTime.Now, SignPublicKey = signPublicKey, AgreePublicKey = agreePublicKey, FingerprintData = new List <string>(), }; var userMetadata = new UserCredMetadata { hashedPassword = EncryptionService.hashPassword(password) }; var asset = new AssetSaved <UserCredAssetData> { Type = AssetType.MLT, Data = userAssetData, RandomId = _random.Next(0, 100000) }; var metadata = new MetaDataSaved <UserCredMetadata> { data = userMetadata }; _bigChainDbService.SendCreateTransactionToDataBase(asset, metadata, signPrivateKey); return(RedirectToAction("Login")); }
public IActionResult PatientSignUp(PatientSignUpViewModel patientSignUpViewModel) { // Description: Registers a patient up for a MedNet account ViewBag.DoctorName = HttpContext.Session.GetString(Globals.currentUserName); string signPrivateKey = null, agreePrivateKey = null, signPublicKey = null, agreePublicKey = null; Assets <PatientCredAssetData> userAsset = _bigChainDbService.GetPatientAssetFromID(patientSignUpViewModel.PHN); // Check if PHN is already in use if (userAsset != null) { ModelState.AddModelError("", "A Patient profile with that PHN already exists"); return(View(patientSignUpViewModel)); } // Register fingerprint information int numScans = 5; List <Image> fpList = FingerprintService.authenticateFP("24.84.225.22", numScans); List <byte[]> fpdb = new List <byte[]>(); if (fpList.Count > numScans) { ModelState.AddModelError("", "Something went wrong with the fingerprint scan, try again."); return(View(patientSignUpViewModel)); } // Parse the input data for user registration var passphrase = patientSignUpViewModel.KeyWord; var password = patientSignUpViewModel.Password; // Encrypt fingerprint data List <string> encrList = new List <string>(); foreach (var fp in fpList) { byte[] fpByte = FingerprintService.imgToByte(fp); string encrStr = EncryptionService.encryptFingerprintData(patientSignUpViewModel.PHN, passphrase, fpByte); encrList.Add(encrStr); } // Create a user for the Blockchain EncryptionService.getNewBlockchainUser(out signPrivateKey, out signPublicKey, out agreePrivateKey, out agreePublicKey); // Create the user Asset var userAssetData = new PatientCredAssetData { ID = patientSignUpViewModel.PHN, DateOfBirth = patientSignUpViewModel.DateOfBirth, PrivateKeys = EncryptionService.encryptPrivateKeys(patientSignUpViewModel.PHN, passphrase, signPrivateKey, agreePrivateKey), DateOfRecord = DateTime.Now, SignPublicKey = signPublicKey, AgreePublicKey = agreePublicKey, FingerprintData = encrList, }; // Encrypt the user's password in the metadata var userMetadata = new PatientCredMetadata { FirstName = patientSignUpViewModel.FirstName, LastName = patientSignUpViewModel.LastName, Email = patientSignUpViewModel.Email, hashedPassword = EncryptionService.hashPassword(password) }; // Save the user Asset and Metadata var asset = new AssetSaved <PatientCredAssetData> { Type = AssetType.Patient, Data = userAssetData, RandomId = _random.Next(0, 100000) }; var metadata = new MetaDataSaved <PatientCredMetadata> { data = userMetadata }; // Send the user's information to the Blockchain database _bigChainDbService.SendCreateTransactionToDataBase(asset, metadata, signPrivateKey); return(RedirectToAction("PatientLookUp")); }