Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am developing a project in C#, for which I want to login/authenticate a user using their fingerprint.
I bought a ZK4500 Fingerprint scanner and got its SDK from http://www.zkteco.com/product/ZK4500_238.html. The SDK is in C++.
So How can I integrate this SDK with my C# project to perform the desired functionality?
You need to add reference to ZKFPEngXControl that will appear under COM Type Libraries. After that you can use the ZKFPEngX Class to do whatever you require.
using ZKFPEngXControl;
and then
ZKFPEngX fp = new ZKFPEngX();
fp.SensorIndex = 0;
fp.InitEngine(); // Do validation as well as it returns an integer (0 for success, else error code 1-3)
//subscribe to event for getting when user places his/her finger
fp.OnImageReceived += new IZKFPEngXEvents_OnImageReceivedEventHandler(fp_OnImageReceived);
You can write your own method fp_OnImageReceived to handle the event. for example you can write this in that method;
object imgdata = new object();
bool b = fp.GetFingerImage(ref imgdata);
Where imgdata is an array of bytes.You can also use other methods in ZKFPEngX, to achieve your goals. Remember to close the engine when form closes.
fp.EndEngine();
You can store a fingerprint under OnEnroll(bool ActionResult, object ATemplate) Event.This event will be called when BeginEnroll() has been executed.
//Add an event handler on OnEnroll Event
ZKFPEngX x = new ZKFPEngX();
x.OnEnroll += X_OnEnroll;
private void X_OnEnroll(bool ActionResult, object ATemplate)
{
if (ActionResult)
{
if (x.LastQuality >= 80) //to ensure the fingerprint quality
{
string regTemplate = x.GetTemplateAsStringEx("9");
File.WriteAllText(Application.StartupPath + "\\fingerprint.txt", regTemplate);
}
else
{
//Quality is too low
}
}
else
{
//Register Failed
}
}
You can try to verify the fingerprints under OnCapture(bool ActionResult, object ATemplate)event. This event will be called when a finger is put on the scanner.
Add an event handler on OnCapture Event:
x.OnCapture += X_OnCapture;
Verify the fingerprints when the event has been called (a finger is put on the scanner):
private void X_OnCapture(bool ActionResult, object ATemplate)
{
if (ActionResult) //if fingerprint is captured successfully
{
bool ARegFeatureChanged = true;
string regTemplate = File.ReadAllText(Application.StartupPath + "\\fingerprint.txt");
string verTemplate = x.GetTemplateAsString();
bool result = x.VerFingerFromStr(regTemplate , verTemplate, false, ARegFeatureChanged);
if (result)
{
//matched
}
else
{
//not matched
}
}
else
{
//failed to capture a valid fingerprint
}
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm creating a unity quiz game using input fields.
How can I use text from an input field to match with an answer in a c# script?
hijinxbassist's example is good, however, i made an example that includes the other parts as well, like adding event listeners and declaring the fields.
Checking for single correct answer:
public Button submitAnswerBtn; // assign a UI button object in editor
public InputField answerInput; // assign a UI inputfield object in editor
private string a1_right_answer = "foo"; // make it public and edit the answer in editor if you like
private void Awake()
{
// add event listener when button for submitting answer is clicked
submitAnswerBtn.onClick.AddListener(() => {
// validate the answer
if(answerInput.text.ToLower() == a1_right_answer) {
// success
Debug.Log("Correct");
} else {
Debug.Error("Wrong");
}
});
Checking for multiple correct answers:
public Button submitAnswerBtn; // assign a UI button object in editor
public InputField answerInput; // assign a UI inputfield object in editor
private string[] a1_right_answers = { "foo", "bar", "foo1", "bar1" }; // multiple right answers
private bool is_right_answer = false; // default value
private void Awake()
{
// add event listener when button for submitting answer is clicked
submitAnswerBtn.onClick.AddListener(() => {
// loop through all the right answers
for (int i = 0; i < a1_right_answers.Length; i++)
{
// validate the answer
if(answerInput.text.ToLower() == a1_right_answers[i]) {
// success
is_right_answer = true;
break;
}
}
// check if the user got the right or wrong answer
if(is_right_answer) {
Debug.Log("Correct");
is_right_answer = false; // reset for next guess
}
else {
Debug.Log("Wrong");
// no need to reset 'is_right_answer' since its value is already default
}
});
I am not sure which part of this problem you are stuck on, but I will attempt to answer.
I think the most important thing when comparing an input field with a stored answer is to make sure the comparison is case insensitive. You can do this by converting both texts to either lowercase or uppercase.
var usersAnswer = answerInputField.text.ToLower();
var actualAnswer = "Some Answer".ToLower();
if (usersAnswer == actualAnswer)
{
Debug.Log("You got it right!");
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to display the battery popup when the user clicks on the tray icon of my application.
I searched around for quite a while but I couldn't find any API for this, neither .NET nor native. Is this possible (e.g. via P/Invoke)? I am using WinForms, but that shouldn't be relevant.
I am speaking of these windows:
You can use Windows UI Automation as explained here: Enumerating notification icons via UI Automation
The difficulty is to find the power icon, whatever the end-user language is. Luckily, some icons have an AutomationId set, so we can search the power one using its id.
There is one issue though: for some reason the UI automation dlls (UIAutomationXXX) shipped with Windows are not up to date (and buggy) so don't use them for this task, and use the UIAComWrapper dll (originally written by a Microsoft guy) instead, for example from here: https://www.nuget.org/packages/UIAComWrapper/
So, here is a sample Console app code (with helper code from the link above):
static void Main(string[] args)
{
// you can find the value of this guid using SDK's "inspect" tool, hovering over the power icon.
var SCAID_Power = new Guid("7820ae75-23e3-4229-82c1-e41cb67d5b9c");
var power = EnumNotificationIcons().FirstOrDefault(i => string.Compare(i.Current.AutomationId, SCAID_Power.ToString("B"), StringComparison.OrdinalIgnoreCase) == 0);
if (power != null)
{
power.InvokeButton();
}
}
public static IEnumerable<AutomationElement> EnumNotificationIcons()
{
var userArea = AutomationElement.RootElement.Find("User Promoted Notification Area");
if (userArea != null)
{
foreach (var button in userArea.EnumChildButtons())
{
yield return button;
}
foreach (var button in userArea.GetTopLevelElement().Find("System Promoted Notification Area").EnumChildButtons())
{
yield return button;
}
}
var chevron = AutomationElement.RootElement.Find("Notification Chevron");
if (chevron != null && chevron.InvokeButton())
{
foreach (var button in AutomationElement.RootElement.Find("Overflow Notification Area").EnumChildButtons())
{
yield return button;
}
}
}
public static class AutomationHelpers
{
public static AutomationElement Find(this AutomationElement root, string name) => root.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, name));
public static IEnumerable<AutomationElement> EnumChildButtons(this AutomationElement parent) => parent == null ? Enumerable.Empty<AutomationElement>() : parent.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button)).Cast<AutomationElement>();
static public AutomationElement GetTopLevelElement(this AutomationElement element)
{
AutomationElement parent;
while ((parent = TreeWalker.ControlViewWalker.GetParent(element)) != AutomationElement.RootElement)
{
element = parent;
}
return element;
}
public static bool InvokeButton(this AutomationElement button)
{
var invokePattern = button.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
invokePattern?.Invoke();
return invokePattern != null;
}
}
Your app should be able to use the same information that the OS uses to display the battery stats. This doesn't mean you should use the same UI as the OS. I don't suppose you can access that programmatically. And if you did, how would you be able to plug it into your application?...
Try querying WMI to get the data you want. Perhaps class Win32_Battery is what you need.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How can I make a TextBox in C# to allow a maximum of one . (dot)?
Thus, abcdef and abc.def would be valid inputs whereas ab.cd.ef wouldn't.
By allow I mean that the user should not be able to enter a dot if there is already one in the text field.
Java has DocumentFilters for that purpose, is there something similar in C#?
I guess this is for validating user inputs. You should create a button and tell the user when he is done, press it so that you can check whether there is only one . in the string.
Assumptions:
Let your text box be called tb. Let your button's Click event handler be BtnOnClick.
Now we can start to write code. First create the handler:
private void BtnOnClick (object sender, EventArgs e) {
}
In the handler, you need to loop through the string and check each character. You can use a foreach for this:
int dotCount = 0;
string s = tb.Text;
if (s.StartsWith(".")) //starts with .
//code to handle invalid input
return;
if (s.EndsWith(".")) //ends with .
//code to handle invalid input
return;
foreach (char c in s) {
if (c == '.') {
dotCount++;
}
if (dotCount >= 2) { //more than two .
//code to handle invalid input
return;
}
}
// if input is valid, this will execute
Alternatively, you can use a query expression. But I think you are unlikely to know what that is.
string s = tb.Text;
if (s.StartsWith(".")) //starts with .
//code to handle invalid input
return;
if (s.EndsWith(".")) //ends with .
//code to handle invalid input
return;
var query = from character in s
where character == '.'
select character;
if (query.Count() > 1) {
//code to handle invalid input
return;
}
// if input is valid, this will execute
This question already has answers here:
Is there an easy way to detect shake motions on Windows Phone 8?
(3 answers)
Closed 8 years ago.
I have created a windows phone app that locates a users location when a button is pressed but I want to do away with the button and make this function occur when the phone is shaken! Below is the code that I have created so far, when the application loads it will call a function called Locate_Me which initializes the Accelerometer.
private async void Locate_Me()
{
if (accelerometer == null)
{
// Instantiate the Accelerometer.
accelerometer = new Accelerometer();
accelerometer.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20);
accelerometer.CurrentValueChanged +=
new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(accelerometer_CurrentValueChanged);
}
try
{
statusTextBlock.Text = "starting accelerometer.";
accelerometer.Start();
}
catch (InvalidOperationException ex)
{
statusTextBlock.Text = "unable to start accelerometer.";
}
}
So how would I go about making the onShaken function?
First step: Download ShakeGestures library from microsoft site here. Add ShakeGetures.dll to your project.
Now it's a piece of cake for you to detect shake gestures. Below is the code you can use:
//constructor of page register event handler for shake
public Page1()
{
InitializeComponent();
// register shake event
ShakeGesturesHelper.Instance.ShakeGesture +=new
EventHandler<ShakeGestureEventArgs>(Instance_ShakeGesture);
// optional, set parameters
ShakeGesturesHelper.Instance.MinimumRequiredMovesForShake = 2;
// start shake detection
ShakeGesturesHelper.Instance.Active = true;
}
private void Instance_ShakeGesture(object sender, ShakeGestureEventArgs e)
{
//call your method
}
This is the minimal code you would require. Worked for me.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
want to ask about void type, so I could know that it works or no
in PHP i could have a condition like this:
if(mysql_query($query))
{ bla bla }
else
{ print error }
how to do like that on ASP.NET?
i'm trying like this:
if (k.EditPassword(username.Text, oldPassTxt.Text, newPassTxt.Text) == true )
{
Response.Redirect("sample.aspx");
}
else
{ print error }
but of course, it cannot be like that, because void isn't boolean
Usually void functions that do work that can fail will have some other way of informing you that they failed. Often they will throw an Exception:
try
{
k.EditPassword(...)
}
catch(ApplicationException ex)
{
// print Exception
}
Response.Redirect(...)
Other times they will set a status variable or something:
k.EditPassword(...)
if (k.Result == Result.OK)
Response.Redirect(...)
else
// print error...
Looking at documentation or source code for the conditions you are trying to handle is the only way to know how to handle it.
You can use a literal control and add your text to it. So your code will go something like,
if (k.EditPassword(username.Text, oldPassTxt.Text, newPassTxt.Text) == true )
{
Response.Redirect("sample.aspx");
}
else
{ Literal1.Text = error; }
Literal should be in design file, you can add it from toolbox.
But a better and proper way would be to,
Log it. (You would need a log mecahnism)
Write a unit test :)