Exemple #1
0
        static public async Task <bool> createUser(User user, string password)
        {
            RestController <User> userController = new RestController <User>();
            var list = await userController.getObjects(WcfConfig.getUserUrl(user.Email));

            if (list.Count != 0)
            {
                return(false);
            }

            RestController <Role>    roleController    = new RestController <Role>();
            RestController <Patient> patientController = new RestController <Patient> ();

            List <Role> roles = await roleController.getObjects(WcfConfig.getRole(RolesKind.PATIENT));

            user.Roles = roles;

            IBuffer buff = CryptographicBuffer.ConvertStringToBinary(password, BinaryStringEncoding.Utf8);
            HashAlgorithmProvider hap = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
            IBuffer shaBuff           = hap.HashData(buff);

            byte[] pass;
            CryptographicBuffer.CopyToByteArray(shaBuff, out pass);
            user.Pass = pass;
            await userController.insertObject(user, WcfConfig.TableUser);

            await patientController.insertObject(new Patient { Pesel = user.Pesel }, WcfConfig.TablePatient);

            return(true);
        }
Exemple #2
0
        static public async Task <bool> authenticateUser(string email, string password)
        {
            RestController <User> controller = new RestController <User>();
            var list = await controller.getObjects(WcfConfig.getUserUrl(email));

            if (list.Count == 0)
            {
                return(false);
            }

            User    user = list.First();
            var     pass = user.Pass;
            IBuffer buff = CryptographicBuffer.ConvertStringToBinary(password, BinaryStringEncoding.Utf8);
            HashAlgorithmProvider hap = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
            IBuffer shaBuff           = hap.HashData(buff);
            IBuffer passDb            = CryptographicBuffer.CreateFromByteArray(pass);
            bool    result            = CryptographicBuffer.Compare(passDb, shaBuff);

            if (result)
            {
                logUser(user);
            }

            return(result);
        }