Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Need help in while entering password

by anandooty (Initiate)
on Aug 18, 2013 at 05:58 UTC ( #1049889=perlquestion: print w/replies, xml ) Need Help??
anandooty has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need help to in putting passwords. I have written a script for login into our application. while running script it should ask for application login name and password. Sometimes users has the password like Team@123, Case$123,etc. Such case it takes only the letters before @, $ and login failed. Can somebody help me to take entire password in case if it contains @, $. NOTE : I can't ask users to don't keep @, $ in your password. Regards, Anand Mathan.

Replies are listed 'Best First'.
Re: Need help in while entering password
by kcott (Chancellor) on Aug 18, 2013 at 06:40 UTC

    G'day Anand,

    Welcome to the monastery.

    I suspect you're doing something like this:

    $ perl -le ' my $password = "abc$def"; print $password; ' abc

    With the warnings pragma, you'd get:

    $ perl -le ' use warnings; my $password = "abc$def"; print $password; ' Name "main::def" used only once: possible typo at -e line 3. Use of uninitialized value $def in concatenation (.) or string at -e l +ine 3. abc

    Now you get a warning (which might get lost in log files, scrolled off the screen, or otherwise not be noticed) but the problem remains (i.e. 'abc' is still output).

    With the strict pragma, you'd get:

    $ perl -le ' use strict; use warnings; my $password = "abc$def"; print $password; ' Global symbol "$def" requires explicit package name at -e line 4. Execution of -e aborted due to compilation errors.

    Now you have an error which would be pretty hard not to notice as your program has aborted before it even started to run. If you follow the strict link I provided, you'll find more information about this under "strict vars".

    So, the first lesson to take away from this is to add

    use strict; use warnings;

    to start of all your scripts (unless you have a very good reason for not doing so).

    Anyway, that's all guesswork on my part as you haven't posted any code. All user input should be viewed as suspicious so I won't be suggesting ways to fix code I haven't seen: I could end up causing you far worse problems than a simple failed login. Have a read of "How do I post a question effectively?" then, following those guidelines, update your post with something we can work with ("How do I change/delete my post?" tells you how to do that).

    -- Ken

Re: Need help in while entering password
by Happy-the-monk (Canon) on Aug 18, 2013 at 06:16 UTC

    anandooty, welcome to the monastery!

    Please show us the code you have so far, and we'll help you along.

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)

Re: Need help in while entering password
by AnomalousMonk (Chancellor) on Aug 18, 2013 at 19:21 UTC

    Happy-the-monk has asked you to show us the code you have so far, but I would be far happier with a small, standalone, runnable code example that demonstrates the problem you are asking about. The effort of creating such an example may, in and of itself, lead to useful insight about the root cause of the problem! Please see How do I post a question effectively?.

      Hi, Here is my code. Here I have hard coded my user name and password but password prompts. For $username1 = $password1, and $username2 = $password2. Here only $username2 = $password2 works. For $username1 = $password1 contains @ and it takes only the character before @ "Case" and it doesn't take entire password. I need you help to overcome this issue. Regards, Anand Mathan.

      use strict; use warnings; my $username1 = "anand"; my $username2 = "girish"; my $password1 = "Case@123"; my $password2 = "Seat123#"; my $path = ("\"c:\\Program Files\\SecureFX\\sfxcl\""); my $server = "gaddwuat02"; @trans_file = ("/Q"." "."c:\\eqsys.txt"." "."sftp://$username:"."$pas +sword"."\@"."$server"); print "@trans_file\n"; my @trans = system("$path @trans_file");
        Here is my code.

        The problem is that your code does not compile under strictures (the  use strict; statement; see strict). If  use strict; is left out and the code is run under warnings alone (the  use warnings; statement), Perl produces a bunch of warnings about uninitialized values and possible typos, warnings you should ponder well. Also take a look at the rules for interpolation discussed in the Quote and Quote-like Operators section of perlop; a careful Reading of this section of The Fine Manual would repay your effort. (Same as  perldoc perlop from the command line.)

        Here is an example of double-quote interpolation and single-quote non-interpolation. (These examples have been given before by others.) An example is also given of entering a string from the command line at a prompt. Note that once successfully entered, 'interpolating' characters do not interpolate further: Perl does not do multi-level or nested interpolation. Perhaps you can build on something like this example to demonstrate the problem(s) you are facing. (Note: I use  qq{double quotes} rather than  "double quotes" on my Windoze command line so that the code will not be cluttered by irruptions of backslashes.)

        >perl -wMstrict -le "my $def = 'hi there'; my @jkl = qw(foo bar); ;; my $str1 = qq{abc$def}; my $str2 = qq{ghi@jkl}; ;; print qq{str1: :$str1:}; print qq{str2: :$str2:}; ;; my $str3 = 'pqr$def'; my $str4 = 'xyz@jkl'; ;; print qq{str3: :$str3:}; print qq{str4: :$str4:}; ;; ;; print 'enter password: '; my $pw = <STDIN>; chomp $pw; ;; print qq{pw: :$pw:} " str1: :abchi there: str2: :ghifoo bar: str3: :pqr$def: str4: :xyz@jkl: enter password: open@sez$me pw: :open@sez$me:
        As the others said, you can't put @ or $ into dobule quotes. Just change it to my $password1 = 'Case@123';

        BTW in Perl, when referring to a file on the system to read, write, execute, etc, you can use the normal Unix like path separator even in Windows. Another trick, by using 'single' quotes to stop interpolation of string contents, you don't need to \\ escape your slashes

        # my $path = ("\"c:\\Program Files\\SecureFX\\sfxcl\""); my $notepad = 'c:/Windows/notepad.exe'; system $notepad, 'C:\Boot.ini';


        Pereant, qui ante nos nostra dixerunt!
Re: Need help in while entering password
by sundialsvc4 (Abbot) on Aug 18, 2013 at 13:37 UTC

    /me nods vigorously ...

    I’d also bet my last dollar that you are using double quotes ... that is to say, doing something in some way that causes Perl to interpolate the string’s content.   (It looks for what it thinks are “variables” in the string, and substitutes them.)   Post an excerpt of your code and we can probably show you the problem immediately ... and what I am saying will be much more clear then.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1049889]
Approved by kcott
[Veltro]: Eily That is just how life rolls. Sometimes you start doing something and only later you start to realize the consequece hehe
[Eily]: Discipulus well, $ for $calar makes sense, I don't know how we would explain the
[Discipulus]: i was given 20 pages of introduction to perl, in eatalian buy a guy who tech us hoou to set up a little linux network: I have to find him a give some red wine
[Discipulus]: it was 1999
[Veltro]: I started programming perl because of while(<>){ s/.../.../} One week later I was programming all kinds of different stuff.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2018-06-22 09:23 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (123 votes). Check out past polls.