Пример #1
0
        private User LoadUser(String username)
        {
            XmlDocument data = new XmlDocument();
            try
            {
                data.Load("users.xml");
            }
            catch (Exception)
            {
                Console.WriteLine("file not found");
            }

            SortedDictionary<String, double> matches = new SortedDictionary<String, double>();

            XmlNodeList users = data.GetElementsByTagName("user");

            foreach (XmlNode user in users)
            {
                if (user["name"].InnerText == username)
                {
                    List<Point2d> tempPts = new List<Point2d>();
                    XmlNode points = user["points"];
                    for (int i = 0; i < points.ChildNodes.Count; i++)
                    {
                        XmlNode point = points.ChildNodes[i];
                        double x = Convert.ToDouble(point["x"].InnerText);
                        double y = Convert.ToDouble(point["y"].InnerText);
                        Point2d tmp = new Point2d(x, y);
                        tempPts.Add(tmp);
                    }
                    XmlNode storedDataXml = user["stored-data"];
                    UserInfoTuple[] storedData = new UserInfoTuple[Util.NUM_STORED_DATA];
                    for (int i = 0; i < storedDataXml.ChildNodes.Count; i++)
                    {
                        XmlNode storedDataTuple = storedDataXml.ChildNodes[i];
                        string reference = Convert.ToString(storedDataTuple["reference"].InnerText);
                        string uname = Convert.ToString(storedDataTuple["username"].InnerText);
                        string password = Convert.ToString(storedDataTuple["password"].InnerText);
                        storedData[i] = new UserInfoTuple(reference, uname, password);
                    }
                    return new User(user["name"].InnerText, user["user-image"].InnerText, tempPts, null, storedData);
                }
            }
            return null;
        }
Пример #2
0
        private void byPass_Click(object sender, RoutedEventArgs e)
        {
            if (data == null)
            {
                data = new XmlDocument();
            }
            this.rescan.Visibility = System.Windows.Visibility.Collapsed;
            this.welcomeMassage.Visibility = System.Windows.Visibility.Collapsed;

            try
            {
                data.Load("users.xml");
            }
            catch (Exception exception)
            {
                Console.WriteLine("file not found");
            }

            SortedDictionary<String, double> matches = new SortedDictionary<String, double>();

            XmlNodeList users = data.GetElementsByTagName("user");

            foreach (XmlNode user in users)
            {
                if (String.Compare(user["name"].InnerText, this.currentUser.name, true) == 0)
                {

                    this.currentUser.imgPath = user["user-image"].InnerText;

                    List<Point2d> tempPts = new List<Point2d>();
                    XmlNode points = user["points"];
                    for (int i = 0; i < points.ChildNodes.Count; i++)
                    {
                        XmlNode point = points.ChildNodes[i];
                        double x = Convert.ToDouble(point["x"].InnerText);
                        double y = Convert.ToDouble(point["y"].InnerText);
                        Point2d tmp = new Point2d(x, y);
                        tempPts.Add(tmp);
                    }

                    this.currentUser.password = tempPts;

                    this.byPass.Visibility = System.Windows.Visibility.Collapsed;
                    this.welcomeMassage.Visibility = System.Windows.Visibility.Visible;
                    this.welcomeMassage.Text = "Hello " + this.currentUser.name + "! " + "Start drawing your pattern when the circle is blue.";
                    userImage = new BitmapImage(new Uri(this.currentUser.imgPath));
                    myImageBox.Source = handSource;
                    this.myImageBox.Visibility = Visibility.Visible;
                    this.sensor.DepthFrameReady += this.SensorDepthFrameReady;
                    this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;
                    Queue<ThreeDAuth.Point2d> passwordQueue = new Queue<ThreeDAuth.Point2d>(this.currentUser.password);
                    gValidator = new ThreeDAuth.GestureValidator(passwordQueue, 20);
                    gValidator.OnCompletedValidation += new CompletedValidation(gValidator_OnCompletedValidation);
                }
            }
        }
Пример #3
0
        public void addUser(List<List<double>> data)
        {
            List<double>[] sorted = new List<double>[7];
            for (int h = 0; h < sorted.Length; h++)
            {
                sorted[h] = new List<double>();
            }

            for (int i = 0; i < data.Count; i++)
            {
                List<double> tmp = data.ElementAt(i);

                for (int j = 0; j < tmp.Count; j++)
                {
                    sorted[j].Add(tmp.ElementAt(j));
                }
            }

            List<Point2d> tempPts = new List<Point2d>();

            // calculate mean and standard deviation
            for (int k = 0; k < sorted.Length; k++)
            {
                List<double> tmp = sorted[k];

                double average = tmp.Average();
                double sumOfSquaresOfDifferences = tmp.Select(val => (val - average) * (val - average)).Sum();
                double sd = Math.Sqrt(sumOfSquaresOfDifferences / (tmp.Count - 1));

                if (sd < 0.0001)
                {
                    sd = .00010101;
                }

                Point2d tempPoint = new Point2d(average, sd);
                tempPts.Add(tempPoint);
            }

            User cur = new User("", "", null, tempPts, null);
            Notify(cur);
        }
Пример #4
0
        public void verifyUser(double[] vals)
        {
            try
            {
                data.Load("users.xml");
            }
            catch (Exception)
            {
                Console.WriteLine("file not found");
            }

            SortedDictionary<String, double> matches = new SortedDictionary<String, double>();

            XmlNodeList users = data.GetElementsByTagName("user");

            foreach (XmlNode user in users)
            {
                double total = 0;
                //Console.WriteLine(user["name"].InnerText);
                XmlNode mets = user["face-params"];

                for (int i = 0; i < mets.ChildNodes.Count; i++)
                {
                    XmlNode met = mets.ChildNodes[i];
                    double mean = Convert.ToDouble(met["mean"].InnerText);
                    double stdev = Convert.ToDouble(met["stdev"].InnerText);

                    double score = getZScore(vals[i], mean, stdev);

                    //Console.WriteLine("Score---------> " + score);
                    if(score >= 1) {
                        total += score;
                    }
                }

                //Console.WriteLine("");

                try {
                    matches.Add(user["name"].InnerText, total);
                } catch (Exception e) {

                }
            }

            String bestMatchName = "New User";
            double bestMatchVal = 100;

            foreach (KeyValuePair<String, double> kvp in matches)
            {
                Console.WriteLine(kvp.Key + "----------------" + kvp.Value);
                if (kvp.Value < bestMatchVal)
                {
                    bestMatchVal = kvp.Value;
                    bestMatchName = kvp.Key;
                }
            }

            if (bestMatchVal <= MAX_DIFF)
            {
                Console.WriteLine(bestMatchName);
                foreach (XmlNode user in users)
                {
                    if (user["name"].InnerText == bestMatchName)
                    {
                        List<Point2d> tempPts = new List<Point2d>();
                        XmlNode points = user["points"];
                        for (int i = 0; i < points.ChildNodes.Count; i++)
                        {
                            XmlNode point = points.ChildNodes[i];
                            double x = Convert.ToDouble(point["x"].InnerText);
                            double y = Convert.ToDouble(point["y"].InnerText);
                            Point2d tmp = new Point2d(x, y);
                            tempPts.Add(tmp);
                        }
                        XmlNode storedDataXml = user["stored-data"];
                        UserInfoTuple[] storedData = new UserInfoTuple[Util.NUM_STORED_DATA];
                        for (int i = 0; i < storedDataXml.ChildNodes.Count; i++)
                        {
                            XmlNode storedDataTuple = storedDataXml.ChildNodes[i];
                            string reference = Convert.ToString(storedDataTuple["reference"].InnerText);
                            string username = Convert.ToString(storedDataTuple["username"].InnerText);
                            string password = Convert.ToString(storedDataTuple["password"].InnerText);
                            storedData[i] = new UserInfoTuple(reference, username, password);
                        }
                        User current = new User(user["name"].InnerText, user["user-image"].InnerText, tempPts, null, storedData);
                        Console.WriteLine(user["name"].InnerText);
                        Notify(current);
                        return;
                    }
                }
            }
            else
            {
                Console.WriteLine("New User");
                User cur = new User("", "", null, null, null);
                Notify(cur);
            }
        }
Пример #5
0
 public bool containsPoint(Point2d point)
 {
     return (point.x >= lowerLeftCorner.x &&
             point.x < upperRightCorner.x &&
             point.y >= lowerLeftCorner.y &&
             point.y < upperRightCorner.y);
 }
Пример #6
0
 private double euclideanDistance(Point2d p1, Point2d p2)
 {
     return Math.Sqrt((p1.x - p2.x) * (p1.x - p2.x) +
                       (p1.y - p2.y) * (p1.y - p2.y));
 }
Пример #7
0
 private double euclideanDistance(Point2d p1, Point2d p2)
 {
     return(Math.Sqrt((p1.x - p2.x) * (p1.x - p2.x) +
                      (p1.y - p2.y) * (p1.y - p2.y)));
 }
Пример #8
0
 public TimePointTuple(long timeMark, Point2d point)
 {
     this.timeMark = timeMark;
     this.point = point.copy();
 }
Пример #9
0
 public Vec2d(Point2d p1, Point2d p2)
 {
     this.p1 = p1;
     this.p2 = p2;
 }
Пример #10
0
 public static Point2d operator +(Point2d firstPoint, Point2d secondPoint)
 {
     Point2d sumPoint = new Point2d();
     sumPoint.x = firstPoint.x + secondPoint.x;
     sumPoint.y = firstPoint.y + secondPoint.y;
     return sumPoint;
 }
Пример #11
0
        public void GivePoint(Point point)
        {
            if (manipulatableTargetPoints.Count > 0)
            {
                if (point is PlanePoint)
                {
                    PlanePoint planePoint = (PlanePoint)point;
                    if (planePoint.inPlane)
                    {
                        Point2d newPoint    = (Point2d)point;
                        Point2d target      = manipulatableTargetPoints.Peek();
                        double  newDistance = Util.euclideanDistance(newPoint, target);
                        if (!_startedPath)
                        {
                            if (newDistance < epsilon)
                            {
                                _startedPath = true;
                                Console.WriteLine("Started path");
                            }
                        }
                        else
                        {
                            if (target != null && !failedAuthentication)
                            {
                                if ((newDistance - 3 * epsilon) > oldDistance)
                                {
                                    // Made a move away from the target point, so failed authentication
                                    failedAuthentication = true;
                                    Console.WriteLine("Failure :( ");
                                    // Give them some time interval to reset it before marking it as a failure

                                    System.Timers.Timer failureTimer = new System.Timers.Timer();
                                    failureTimer.Elapsed  += new System.Timers.ElapsedEventHandler(failureTimer_Elapsed);
                                    failureTimer.Interval  = 3000;
                                    failureTimer.AutoReset = false;
                                    failureTimer.Enabled   = true;
                                }
                                else
                                {
                                    if (newDistance < epsilon)
                                    {
                                        // Hit the target point, so remove it and target the next one
                                        Console.WriteLine("Hit a target point");
                                        completedTargets.Enqueue(manipulatableTargetPoints.Dequeue());
                                        if (manipulatableTargetPoints.Count > 0)
                                        {
                                            oldDistance = Util.euclideanDistance(newPoint, manipulatableTargetPoints.Peek());
                                        }
                                        else
                                        {
                                            // Validated successfully
                                            timer.Stop();
                                            Console.WriteLine("*** Successfully Validated ***");
                                            ValidationComplete();
                                        }
                                    }
                                    else
                                    {
                                        // Didn't hit the target point, but getting closer
                                        oldDistance = newDistance;
                                    }
                                }
                            }
                            Notify();
                        }
                    }
                }
            }
        }