コード例 #1
0
        // THIS FUNCTION RETURNS RETRIVES THE ACCOUNT SALT CREDENTIALS FROM
        // DATABASE BY AUTHENTICATING USER'S EMAIL ADDRESS
        private async Task <AccountSalt> retrieveAccountSalt(string userEmail)
        {
            try
            {
                // https://tsx3rnuidi.execute-api.us-west-1.amazonaws.com/dev/api/v2/AccountSalt/?email=annrupp22%40gmail.com

                UriBuilder builder = new UriBuilder("https://tsx3rnuidi.execute-api.us-west-1.amazonaws.com/dev/api/v2/AccountSalt");
                builder.Query = "email=" + userEmail.ToLower();

                // Console.WriteLine("builder " + builder);
                // Console.WriteLine("builderq " + builder.Query);

                var result = await client.GetStringAsync(builder.Uri);

                AccountSaltResponse data = new AccountSaltResponse();
                data = JsonConvert.DeserializeObject <AccountSaltResponse>(result);

                AccountSalt userInformation = new AccountSalt
                {
                    password_algorithm = data.result[0].password_algorithm,
                    password_salt      = data.result[0].password_salt
                };

                // Console.WriteLine("Line 349: This is the password_algorithm = " + userInformation.password_algorithm);
                // Console.WriteLine("Line 350: This is the password_salt = " + userInformation.password_salt);

                return(userInformation);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #2
0
        // uses account salt api to retrieve the user's account salt
        // account salt is used to find the user's hashed password
        public async Task <AccountSalt> retrieveAccountSalt(string userEmail)
        {
            try
            {
                /*
                 * var url = accountSaltUrl + userEmail;
                 * System.Diagnostics.Debug.WriteLine("url " + url);
                 * var content = await client.GetStringAsync(accountSaltUrl + userEmail); // get the requested account salt
                 * var accountSalt = JsonConvert.DeserializeObject<AccountSalt>(content);
                 * System.Diagnostics.Debug.WriteLine("try" + accountSalt);
                 *
                 * //System.Diagnostics.Debug.WriteLine("account salt good " + accountSalt.result[0].password_salt);
                 * //System.Diagnostics.Debug.WriteLine("account salt good " + accountSalt.result[0].password_algorithm);
                 * return accountSalt;
                 */

                /*
                 * var request = new HttpRequestMessage();
                 *
                 * request.RequestUri = new Uri(accountSaltUrl);
                 */
                UriBuilder builder = new UriBuilder("https://ht56vci4v9.execute-api.us-west-1.amazonaws.com/dev/api/v2/accountsalt");
                builder.Query = "[email protected]";
                System.Diagnostics.Debug.WriteLine("builder " + builder);
                System.Diagnostics.Debug.WriteLine("builderq " + builder.Query);

                var result = await client.GetStringAsync(builder.Uri);

                Console.WriteLine("result line 287 = " + result);

                /*
                 * using (StreamReader sr = new StreamReader(result.Content.ReadAsStreamAsync().Result))
                 * {
                 *  Console.WriteLine(sr.ReadToEnd());
                 * }
                 */
                /*
                 *
                 * request.Method = HttpMethod.Get;
                 *
                 * var client = new HttpClient();
                 * HttpResponseMessage response = await client.SendAsync(request);
                 *
                 * string items = await response.Content.ReadAsStringAsync();
                 */
                Console.WriteLine("line 303");
                AccountSalt data = new AccountSalt();
                Console.WriteLine("line 305");
                data = JsonConvert.DeserializeObject <AccountSalt>(result);
                Console.WriteLine("line 307 Data: " + data.result[0].password_salt.ToString());

                return(data);
            }
            catch (Exception ex)
            {
                Console.WriteLine("line 313");
                return(null);
            }
            //return null;
        }
コード例 #3
0
        private async Task <AccountSalt> retrieveAccountSalt(string userEmail)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine(userEmail);

                SaltPost saltPost = new SaltPost();
                saltPost.email = userEmail;

                var saltPostSerilizedObject = JsonConvert.SerializeObject(saltPost);
                var saltPostContent         = new StringContent(saltPostSerilizedObject, Encoding.UTF8, "application/json");

                System.Diagnostics.Debug.WriteLine(saltPostSerilizedObject);

                var client      = new HttpClient();
                var DRSResponse = await client.PostAsync(Constant.AccountSaltUrl, saltPostContent);

                var DRSMessage = await DRSResponse.Content.ReadAsStringAsync();

                System.Diagnostics.Debug.WriteLine(DRSMessage);

                AccountSalt userInformation = null;

                if (DRSResponse.IsSuccessStatusCode)
                {
                    var result = await DRSResponse.Content.ReadAsStringAsync();

                    AcountSaltCredentials data = new AcountSaltCredentials();
                    data = JsonConvert.DeserializeObject <AcountSaltCredentials>(result);

                    if (DRSMessage.Contains(Constant.UseSocialMediaLogin))
                    {
                        createAccount = true;
                        System.Diagnostics.Debug.WriteLine(DRSMessage);
                        await DisplayAlert("Oops!", data.message, "OK");
                    }
                    else if (DRSMessage.Contains(Constant.EmailNotFound))
                    {
                        await DisplayAlert("Oops!", "Our records show that you don't have an accout. Please sign up!", "OK");
                    }
                    else
                    {
                        userInformation = new AccountSalt
                        {
                            password_algorithm = data.result[0].password_algorithm,
                            password_salt      = data.result[0].password_salt
                        };
                    }
                }

                return(userInformation);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
コード例 #4
0
ファイル: UserService.cs プロジェクト: k-lisa/ymc-full
        /// <summary>
        /// The Dataprovider call to get the Salt for User with the given UserName/Email
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        private string GetSalt(string email)
        {
            //throw new NotImplementedException();
            //DataProvider Call to get Salt
            AccountSalt salt = null;

            _dataProvider.ExecuteCmd("dbo.Person_SelectSaltByEmail",
                                     inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Email", email);
            },
                                     singleRecordMapper : delegate(IDataReader reader, short set)
            {
                salt      = new AccountSalt();
                int ord   = 0;
                salt.Salt = reader.GetSafeString(ord++);
            });

            return(salt.Salt);
        }
コード例 #5
0
ファイル: LogIn.xaml.cs プロジェクト: infinite-options/login
        private async Task <AccountSalt> retrieveAccountSalt(string userEmail)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine(userEmail);

                SaltPost saltPost = new SaltPost();
                saltPost.email = userEmail;

                var saltPostSerilizedObject = JsonConvert.SerializeObject(saltPost);
                var saltPostContent         = new StringContent(saltPostSerilizedObject, Encoding.UTF8, "application/json");

                var client      = new HttpClient();
                var DRSResponse = await client.PostAsync(Constant.AccountSaltUrl, saltPostContent);

                AccountSalt userInformation = null;
                if (DRSResponse.IsSuccessStatusCode)
                {
                    var result = await DRSResponse.Content.ReadAsStringAsync();

                    AcountSaltCredentials data = new AcountSaltCredentials();
                    data = JsonConvert.DeserializeObject <AcountSaltCredentials>(result);

                    userInformation = new AccountSalt
                    {
                        password_algorithm = data.result[0].password_algorithm,
                        password_salt      = data.result[0].password_salt
                    };
                }

                return(userInformation);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
コード例 #6
0
ファイル: LogIn.xaml.cs プロジェクト: infinite-options/login
        public async Task <LogInResponse> LogInUser(string userEmail, string userPassword, AccountSalt accountSalt)
        {
            try
            {
                SHA512 sHA512         = new SHA512Managed();
                byte[] data           = sHA512.ComputeHash(Encoding.UTF8.GetBytes(userPassword + accountSalt.password_salt)); // take the password and account salt to generate hash
                string hashedPassword = BitConverter.ToString(data).Replace("-", string.Empty).ToLower();                     // convert hash to hex

                LogInPost loginPostContent = new LogInPost();
                loginPostContent.email    = userEmail;
                loginPostContent.password = hashedPassword;

                string loginPostContentJson = JsonConvert.SerializeObject(loginPostContent);                  // make orderContent into json

                var httpContent = new StringContent(loginPostContentJson, Encoding.UTF8, "application/json"); // encode orderContentJson into format to send to database
                var response    = await client.PostAsync(Constant.LogInUrl, httpContent);                     // try to post to database


                if (response.Content != null)
                {
                    var responseContent = await response.Content.ReadAsStringAsync();

                    var loginResponse = JsonConvert.DeserializeObject <LogInResponse>(responseContent);
                    return(loginResponse);
                }
                return(null);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception message: " + e.Message);
                return(null);
            }
        }
コード例 #7
0
        // logs the user into the app
        // returns a LoginResponse if successful and null if unsuccessful
        //public async Task<LoginResponse> login(string userEmail, string userPassword, AccountSalt accountSalt)
        public async void login(string userEmail, string userPassword, AccountSalt accountSalt)
        {
            Console.WriteLine("login email" + userEmail);
            Console.WriteLine("login pw" + userPassword);
            Console.WriteLine("login acct salt" + accountSalt);

            const string deviceBrowserType = "Mobile";
            var          deviceIpAddress   = Dns.GetHostAddresses(Dns.GetHostName()).FirstOrDefault();

            //var deviceIpAddress = "0.0.0.0";
            if (deviceIpAddress != null)
            {
                try
                {
                    /*
                     * LoginPost loginPostContent = new LoginPost()
                     * { // object that contains ip address and browser type; will be converted into a json object
                     *  ipAddress = deviceIpAddress.ToString(),
                     *  browserType = deviceBrowserType
                     * };
                     *
                     * string loginPostContentJson = JsonConvert.SerializeObject(loginPostContent); // make orderContent into json
                     *
                     * var httpContent = new StringContent(loginPostContentJson, Encoding.UTF8, "application/json"); // encode orderContentJson into format to send to database
                     */

                    /*
                     * UserInfo ui = new UserInfo()
                     * {
                     *  email = "*****@*****.**",
                     *  password = "******"
                     * };
                     */



                    SHA512 sHA512 = new SHA512Managed();
                    Console.WriteLine("sha " + sHA512);

                    byte[] data = sHA512.ComputeHash(Encoding.UTF8.GetBytes(userPassword + accountSalt.result[0].password_salt)); // take the password and account salt to generate hash
                    Console.WriteLine("data " + data[0]);

                    string hashedPassword = BitConverter.ToString(data).Replace("-", string.Empty).ToLower(); // convert hash to hex

                    UserInfo ui = new UserInfo()
                    {
                        email    = userEmail,
                        password = hashedPassword,
                    };

                    Console.WriteLine("hash pw " + hashedPassword);

                    var data2   = JsonConvert.SerializeObject(ui);
                    var content = new StringContent(data2, Encoding.UTF8, "application/json");
                    Console.WriteLine("data2 " + data2);
                    Console.WriteLine("after content 176");
                    Console.WriteLine("login url " + loginUrl);

                    using (var httpClient = new HttpClient())
                    {
                        Console.WriteLine("HTTPclient " + httpClient);

                        Console.WriteLine("inside using");

                        var request1 = new HttpRequestMessage();
                        Console.WriteLine("request " + request1);

                        request1.Method = HttpMethod.Post;
                        Console.WriteLine("rq method " + request1.Method);

                        request1.Content = content;
                        Console.WriteLine("request ctnt " + request1.Content);

                        var httpResponse = await httpClient.PostAsync(loginUrl, content);

                        //HttpResponseMessage response = await httpClient.SendAsync(request);
                        //Console.WriteLine("This is the response from request" + response);

                        /*
                         * var endpointresponse = await httpClient.GetAsync(loginUrl);
                         * string jsonobject = endpointresponse.Content.ReadAsStringAsync().Result;
                         * var data3 = httpClient.GetStringAsync(loginUrl);
                         * Console.WriteLine("data 3 " + httpResponse.RequestMessage.Content);
                         */
                    }
                    Console.WriteLine("after 208");

                    /*
                     * var request = new HttpRequestMessage();
                     * request.RequestUri = new Uri(loginUrl);
                     * request.Method = HttpMethod.Post;
                     * request.Content = content;
                     *
                     * var client = new HttpClient();
                     * HttpResponseMessage response = await client.SendAsync(request);
                     * string items = await response.Content.ReadAsStringAsync();
                     * Console.WriteLine("items " + items);
                     */
                    //string uiString = JsonConvert.SerializeObject(ui);
                    //var httpContent = new StringContent(uiString, Encoding.UTF8, "application/json"); // encode orderContentJson into format to send to database

                    /*
                     * SHA512 sHA512 = new SHA512Managed();
                     * byte[] data = sHA512.ComputeHash(Encoding.UTF8.GetBytes(userPassword + accountSalt.result[0].passwordSalt)); // take the password and account salt to generate hash
                     * string hashedPassword = BitConverter.ToString(data).Replace("-", string.Empty).ToLower(); // convert hash to hex
                     *
                     */

                    //var respString = loginUrl + userEmail + "/" + hashedPassword;
                    //var respString = loginUrl;
                    //var response = await client.PostAsync(respString, httpContent); // try to post to database
                    //var response = await client.PostAsync(respString, httpContent); // try to post to database
                    //var answer = await client.GetStringAsync(loginUrl);
                    //Console.WriteLine("Answer " + answer);

                    /*
                     * if (response.Content != null)
                     * { // post was successful
                     *  var responseContent = await response.Content.ReadAsStringAsync();
                     *  var loginResponse = JsonConvert.DeserializeObject<LoginResponse>(responseContent);
                     *  System.Diagnostics.Debug.WriteLine("URL: " + respString + "\n" + uiString + "\n " + loginResponse);
                     *
                     *  return loginResponse;
                     *
                     * }
                     */
                }
                catch (Exception e)
                {
                    Console.WriteLine("catch 225");

                    System.Diagnostics.Debug.WriteLine("Exception message: " + e.Message);
                    //return null;
                }
            }
            //return null;
        }
コード例 #8
0
        // THIS FUNCTION IS LOGS IN THE USER IF THEIR ACCOUNT INFORMATION MATCHES
        // WITH DATABASE KEYS
        private async void login(string userEmail, string userPassword, AccountSalt accountSalt)
        {
            try
            {
                SHA512 sHA512 = new SHA512Managed();
                Console.WriteLine("sha " + sHA512);

                byte[] data = sHA512.ComputeHash(Encoding.UTF8.GetBytes(userPassword + accountSalt.password_salt)); // take the password and account salt to generate hash
                Console.WriteLine("data " + data[0]);

                string hashedPassword = BitConverter.ToString(data).Replace("-", string.Empty).ToLower(); // convert hash to hex

                UserInfo ui = new UserInfo()
                {
                    email    = userEmail,
                    password = hashedPassword,
                };

                var data2   = JsonConvert.SerializeObject(ui);
                var content = new StringContent(data2, Encoding.UTF8, "application/json");

                using (var httpClient = new HttpClient())
                {
                    var request = new HttpRequestMessage();
                    request.Method  = HttpMethod.Post;
                    request.Content = content;
                    var httpResponse = await httpClient.PostAsync("https://tsx3rnuidi.execute-api.us-west-1.amazonaws.com/dev/api/v2/Login", content);

                    var message = await httpResponse.Content.ReadAsStringAsync();

                    var user = JsonConvert.DeserializeObject <UserAcount>(message);
                    isUserLoggedIn = httpResponse.IsSuccessStatusCode;

                    Application.Current.Properties["customer_uid"]             = user.result[0].customer_uid;
                    Application.Current.Properties["userFirstName"]            = user.result[0].customer_first_name;
                    Application.Current.Properties["userLastName"]             = user.result[0].customer_last_name;
                    Application.Current.Properties["userEmailAddress"]         = user.result[0].customer_email;
                    Application.Current.Properties["userAddress"]              = user.result[0].customer_address;
                    Application.Current.Properties["userAddressUnit"]          = user.result[0].customer_unit;
                    Application.Current.Properties["userCity"]                 = user.result[0].customer_city;
                    Application.Current.Properties["userState"]                = user.result[0].customer_state;
                    Application.Current.Properties["userZipCode"]              = user.result[0].customer_zip;
                    Application.Current.Properties["latitude"]                 = user.result[0].customer_lat;
                    Application.Current.Properties["longitude"]                = user.result[0].customer_long;
                    Application.Current.Properties["userDeliveryInstructions"] = "";
                    Application.Current.Properties["userPhoneNumber"]          = user.result[0].customer_phone_num;

                    Console.WriteLine("This is your response content = " + message);
                    Console.WriteLine("This is the JSON object = " + httpResponse.IsSuccessStatusCode);
                    Console.WriteLine("This is the value of isUserLoggedIn = " + isUserLoggedIn);

                    if (isUserLoggedIn)
                    {
                        Application.Current.MainPage = new NewUI.StartPage();
                    }
                    else
                    {
                        await DisplayAlert("Log In Message", "It looks like your weren't able to log in. Try one more time!", "OK");
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception message: " + e.Message);
            }
        }
コード例 #9
0
        // DIRECT VERIFICATION FUNCTIONS_______________________________________

        // This function retrives direct user's account salt credentials.

        public async Task <AccountSalt> RetrieveAccountSalt(string userEmail)
        {
            AccountSalt userInformation = null;

            try
            {
                SaltPost saltPost = new SaltPost();
                saltPost.email = userEmail;

                var saltPostSerilizedObject = JsonConvert.SerializeObject(saltPost);
                var saltPostContent         = new StringContent(saltPostSerilizedObject, Encoding.UTF8, "application/json");

                var client      = new HttpClient();
                var DRSResponse = await client.PostAsync(Constant.AccountSaltUrl, saltPostContent);

                var DRSMessage = await DRSResponse.Content.ReadAsStringAsync();

                if (DRSResponse.IsSuccessStatusCode)
                {
                    var result = await DRSResponse.Content.ReadAsStringAsync();

                    AcountSaltCredentials data = new AcountSaltCredentials();
                    data = JsonConvert.DeserializeObject <AcountSaltCredentials>(result);

                    if (DRSMessage.Contains(Constant.UseSocialMediaLogin))
                    {
                        userInformation = new AccountSalt
                        {
                            password_algorithm = null,
                            password_salt      = null,
                            message            = data.message == null ? "" : data.message
                        };
                    }
                    else if (DRSMessage.Contains(Constant.EmailNotFound))
                    {
                        userToSignUp          = new SignUpAccount();
                        userToSignUp.email    = userEmail.ToLower().Trim();
                        userToSignUp.platform = "DIRECT";

                        userInformation = new AccountSalt
                        {
                            password_algorithm = null,
                            password_salt      = null,
                            message            = "USER NEEDS TO SIGN UP"
                        };
                    }
                    else
                    {
                        userInformation = new AccountSalt
                        {
                            password_algorithm = data.result[0].password_algorithm,
                            password_salt      = data.result[0].password_salt,
                            message            = null
                        };
                    }
                }
            }
            catch (Exception errorRetrieveAccountSalt)
            {
                //var client = new Diagnostic();
                //client.parseException(errorRetrieveAccountSalt.ToString(), user);

                Debug.WriteLine("ERROR ");
            }

            return(userInformation);
        }
コード例 #10
0
        // This function verifies if credentails exist and whether or not user is
        // authenticated by our system. (Overloading)

        public async Task <string> VerifyUserCredentials(string userEmail, string userPassword, AccountSalt accountSalt)
        {
            string isUserVerified = "";

            try
            {
                SHA512 sHA512         = new SHA512Managed();
                var    client         = new HttpClient();
                byte[] data           = sHA512.ComputeHash(Encoding.UTF8.GetBytes(userPassword + accountSalt.password_salt));
                string hashedPassword = BitConverter.ToString(data).Replace("-", string.Empty).ToLower();

                LogInPost loginPostContent = new LogInPost();
                loginPostContent.email           = userEmail;
                loginPostContent.password        = hashedPassword;
                loginPostContent.social_id       = "";
                loginPostContent.signup_platform = "";

                string loginPostContentJson = JsonConvert.SerializeObject(loginPostContent);

                var httpContent = new StringContent(loginPostContentJson, Encoding.UTF8, "application/json");
                var response    = await client.PostAsync(Constant.LogInUrl, httpContent);

                if (response.IsSuccessStatusCode)
                {
                    var responseContent = await response.Content.ReadAsStringAsync();

                    var authetication = JsonConvert.DeserializeObject <RDSAuthentication>(responseContent);

                    if (authetication.code.ToString() == Constant.EmailNotFound)
                    {
                        userToSignUp          = new SignUpAccount();
                        userToSignUp.email    = userEmail.ToLower().Trim();
                        userToSignUp.password = userPassword.Trim();
                        userToSignUp.platform = "DIRECT";

                        isUserVerified = "USER NEEDS TO SIGN UP";
                    }
                    else if (authetication.code.ToString() == Constant.AutheticatedSuccesful)
                    {
                        DateTime today   = DateTime.Now;
                        DateTime expDate = today.AddDays(Constant.days);

                        user             = new User();
                        user.id          = authetication.result[0].driver_uid;
                        user.sessionTime = expDate;
                        user.platform    = "DIRECT";
                        user.email       = "";
                        user.socialId    = "";
                        user.route_id    = "";

                        //var notificationStatus = await SetUserRemoteNotification();

                        //isUserVerified = EvaluteUserUpdates(notificationStatus);

                        isUserVerified = "SUCCESSFUL:0";

                        SaveUser(user);
                    }
                    else if (authetication.code.ToString() == Constant.ErrorPlatform)
                    {
                        //var RDSCode = JsonConvert.DeserializeObject<RDSLogInMessage>(responseContent);

                        isUserVerified = "WRONG SOCIAL MEDIA TO SIGN IN";
                    }
                    else if (authetication.code.ToString() == Constant.ErrorUserDirectLogIn)
                    {
                        isUserVerified = "WRONG DIRECT PASSWORD";
                    }
                }
            }
            catch (Exception errorLogInUser)
            {
                //var client = new Diagnostic();
                //client.parseException(errorLogInUser.ToString(), user);

                Debug.WriteLine("ERROR THE 'errorLogInUser' FUNCTION: " + errorLogInUser.Message);
            }

            return(isUserVerified);
        }